ios - 如何将 tintColor 保留在 UIButton 中然后单击它?

标签 ios objective-c uibutton

我正在将 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/

相关文章:

ios - 将 UIButton 作为 subview 添加到 UITabBar

iphone - 在 iPhone 中的两个 View Controller 之间使用委托(delegate)

iphone - 使用 Core Data 图像填充 tableView

ios - 如何正确地将 iAd 横幅放置在选项卡 Controller 上?

ios - 自定义 UIButton isSelected 背景颜色未按预期工作(IOS/Swift)

iphone - NSMutableArray UIButtons Action ?

ios - 在ios app-Swift中以固定距离对齐两个按钮图像

ios - 身份验证过程后存储用户对象的最佳做法

ios - 导航项左侧和顶部未显示

ios - 如何使用 Obj-C 在 iOS 中播放 mp3