How can I change image tintColor

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

    In swift 2.0 you can use this

    let image = UIImage(named:"your image name")?.imageWithRenderingMode(.AlwaysTemplate)
    let yourimageView.tintColor = UIColor.redColor()
    yourimageView.image = image
    

    In swift 3.0 you can use this

    let image = UIImage(named:"your image name")?.withRenderingMode(.alwaysTemplate)
    let yourimageView.tintColor = UIColor.red
    yourimageView.image = image
    

提交回复
热议问题