简体   繁体   中英

IOS/Objective-C: Set imagerenderingmode of image with Storyboard and code

I created a button in storyboard and I now want to change its tint in code. Changing the tint alone has no effect as I think I need to set the UIImageRenderingMode. However, my code is not working:

Can anyone suggest syntax to change uiimagerenderingmode in code when the button was created in storyboard?

FOLLOWING HAS NO EFFECT:

 self.callButton.imageView.tintColor = [UIColor redColor];

FOLLOWING THROWS ERROR property uiimagerenderingmodealwaystemplate not found :

[self.callButton.image.imageWithRenderingMode UIImageRenderingModeAlwaysTemplate];

Thanks for any suggestions.

One way to solve this:

In your storyboard, make sure to set "Render as" to "Template Image" (the image itself should be black & white) and then you can call self.callButton.tintColor = [UIColor redColor] .

like this:

模板图片

ps I'm using a PDF file for my image, which is why I have the "Single Scale" selected and "Preserve Vector Data" checkbox set to on; if you're using PNG, that checkbox should be set to off and you should have @2x graphics.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM