How can I change image tintColor

后端 未结 13 873
时光说笑
时光说笑 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:45

    - SWIFT 4

    extension UIImage {
        func imageWithColor(_ color: UIColor) -> UIImage? {
            var image: UIImage? = withRenderingMode(.alwaysTemplate)
            UIGraphicsBeginImageContextWithOptions(size, false, scale)
            color.set()
            image?.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
            image = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
            return image
        }
    }
    

提交回复
热议问题