I have a swipe action to \'complete\' a task in my to-do list app. This is the image I have set:
However when the cell is swiped, the image looks like this:
In came up with this extension for 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))
}
}
}
It returns a new icon in the new color when used like this:
swipAction.image = UIImage(named: "myImage")?.colored(in: .white)
Maybe this helps someone.