How can I change image tintColor

后端 未结 13 868
时光说笑
时光说笑 2020-12-13 00:04

I\'m receiving image from a server, then based on a color chosen by the user, the image color will be changed.

I tried the following :

_sketchImageVi         


        
13条回答
  •  醉酒成梦
    2020-12-13 00:46

    For Swift 3.0, I made a custom subclass of UIImageView called TintedUIImageView. Now the image uses whatever tint color is set in interface builder or code

    class TintedUIImageView: UIImageView {
    
        override func awakeFromNib() {
            if let image = self.image {
                self.image = image.withRenderingMode(.alwaysTemplate)
            }
        }
    }
    

提交回复
热议问题