ios - TableViewCell 滑动 Action 中的图像

标签 ios swift uitableview uiswipeactionsconfiguration

我有一个滑动 Action 来“完成”我的待办事项列表应用程序中的任务。这是我设置的图像:

enter image description here

然而,当单元格被滑动时,图像看起来像这样:

Swiped image

有没有办法让背景透明/白色,图像像上图一样有绿色圆圈?

如果没有,有没有办法让绿色背景“换行”到单元格的紫色,这样就没有空格了? 谢谢!

最佳答案

为 UIImage 提出了这个扩展:

    extension UIImage {
        func colored(in color: UIColor) -> UIImage {
            let renderer = UIGraphicsImageRenderer(size: size)
            return renderer.image { context in
                color.set()
                self.withRenderingMode(.alwaysTemplate).draw(in: CGRect(origin: .zero, size: size))
            }
        }
    }

像这样使用时,它会返回一个新颜色的新图标:

        swipAction.image = UIImage(named: "myImage")?.colored(in: .white)

也许这对某人有帮助。

关于ios - TableViewCell 滑动 Action 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51582080/

相关文章:

swift - 在 Swift 中用逗号分隔多个 if 条件

ios - UIScrollView 内的 UITableView 在滚动后没有收到第一次点击

ios - 在 iOS 中创建基于卡片的 UI

ios - 空结果集的 NSExpressionDescription

ios - 在标签IOS之间跳转时ViewController变为空白

ios - reloadRowsAtIndexPaths 导致单元格闪烁或闪烁

Swift:乘法和括号计算不起作用

ios - Swift 2 - NSJSONSerialization.JSONObjectWithData 处理错误

ios - 适用于 iPhone 的真实表格组件

ios - 允许在一个部分中仅检查一个 UITableViewCell