在那里,我想改变图像的色调颜色,但无法改变,它总是返回白色。我已经尝试了原始图像和模板图像的Rendring图像,但仍然不起作用。
我在下面添加了屏幕截图:

请,任何人都可以帮助我
public func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard let cell = tableView.cellForRow(at: indexPath) as? DocumentListCell else {return UISwipeActionsConfiguration()}
let likeAction = UIContextualAction(style: .normal, title: "", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("likeAction ...")
success(true)
})
likeAction.image = #imageLiteral(resourceName: "Favourite_Selected")
likeAction.backgroundColor = UIColor.init(red: 239/255, green: 239/255, blue: 239/255, alpha: 1)
let downloadAction = UIContextualAction(style: .normal, title: "", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("Trash action ...")
})
downloadAction.backgroundColor = UIColor.red//UIColor.init(red: 239/255, green: 239/255, blue: 239/255, alpha: 1)
downloadAction.image = #imageLiteral(resourceName: "Doc_Download_Big")
return UISwipeActionsConfiguration(actions: [likeAction,downloadAction])
}发布于 2019-11-20 23:30:12
Assets.xcassets,选择所需的图像。将
Render As替换为您需要的:

加法
您还可以尝试以下几种方法:
tableView中的
UIImageView本身的设置UIImageView.appearance(whenContainedInInstancesOf: [UITableView.self]).tintColor = UIColor.init(red: 239/255, green: 239/255, blue: 239/255, alpha: 1)UIImage上使用扩展
extension UIImage {
func paintOver(with color: UIColor) -> UIImage {
let renderer = UIGraphicsImageRenderer(size: size)
let renderedImage = renderer.image { _ in
color.set()
self.withRenderingMode(.alwaysTemplate).draw(in: CGRect(origin: .zero, size: size))
}
return renderedImage
}
}使用方法:
likeAction.image = UIImage(named: "Favourite_Selected")?.colored(in: .red)希望这篇文章能帮到你!
发布于 2019-12-15 02:59:40
要更改图像颜色,必须将背景颜色设置为alpha零。
就像下面这行:
likeAction.backgroundColor =UIColor.init(红色: 239/255,绿色: 239/255,蓝色: 239/255,alpha: 0)
https://stackoverflow.com/questions/58957481
复制相似问题