我正在将 tintColor 设置为 UIButton 的 UIImageView,如下所示:
UIImage* img = [UIImage imageNamed:imageName];
icon.image = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
icon.tintColor = [UIColor greenColor];
这段代码是有效的,但是点击 UIButton,颜色返回到 UIImage 的初始颜色。
如何保持添加的绿色?
谢谢!
最佳答案
如果有帮助,请尝试这样。
UIImage *image = [[UIImage imageNamed:@“imageName.png”] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[_yourBtn setImage:image forState:UIControlStateNormal];
[_yourBtn setTintColor:[UIColor greenColor]];
关于ios - 如何将 tintColor 保留在 UIButton 中然后单击它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47960294/