I am playing around with tint colours on a UIImage
and a UIButton
.
On the UIButton
(when the button type is set to System), I am able to set the tint colour of the UIButton
in Xcode by going to Attributes Inspector -> View -> Tint
On UIImageView
, I have set the same image, but when I go to the Attributes Inspector -> View -> Tint, the colour of the image does not change.
Why is the behaviour like this ? and how do I fix it ?
I am using iOS 7 and Xcode 5.1.1
Your image's rendering mode needs to be set to template and not original. To do this, you can call the -[UIImage imageWithRenderingMode:]
method on your image and pass in UIImageRenderingModeAlwaysTemplate
, then set your image view's image to the resulting image:
yourImageView.image = [yourImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
Or, in Swift:
yourImageView.image = yourImage.imageWithRenderingMode(.AlwaysTemplate)