简体   繁体   中英

UIButton image tint not working

One of my apps has three UIButtons on it, and they use images that I got from icons8. In the code, I change the tint color and it works fine. Whatever I set the tint color to is what color the button image becomes that color.

Today I wanted to add a fourth button to mute sound. I downloaded the images that I wanted from icons8, added the button and set it up like I have the rest of the buttons set up. The new button is not changing colors like the rest of them. I'm certain that it has to do with the image, because if I select a different image, it changes color. I also tried using the new image on one of the older buttons and it would not change color.

My question - is there anything special that needs to be done to an image to make it work with tint color?

Try setting the image to render as a template image. You can do this in your .xcasset folder selecting the image set, opening the attributes inspector and setting render as to "template image."

在此处输入图片说明

What I did was follow the @beyowulf instructions and on the code I just did this

yourBtn.tintColor = .white (or other color)

this worked for me

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