How to change the color of an UIImage

后端 未结 7 491

I want not to change the backgroundColor of an UIImage,
but rather to change the color of the whole image.

Because I have got standard forms which I can move fr

7条回答
  •  佛祖请我去吃肉
    2020-12-02 08:13

    For swift 3.2 and 4

    extension UIImageView{
        func changePngColorTo(color: UIColor){
            guard let image =  self.image else {return}
            self.image = image.withRenderingMode(.alwaysTemplate)
            self.tintColor = color
        }
    }
    

    Use :

    self.yourImageView.changePngColorTo(color: .red)
    

提交回复
热议问题