ios - UIButton 色调颜色影响处于选中状态的按钮的背景颜色

标签 ios iphone uibutton tintcolor

我有一个带有 typeSystem 的按钮,它在正常状态下有一个特定的图像,在选定状态下有一个不同的图像。问题是,当我将我的按钮设置为选中状态时,图像不会显示,并且按钮的背景颜色为淡色。 有什么办法可以阻止它发生并显示我为选定状态设置的图像吗?

最佳答案

而不是使用 buttonWithType:UIButtonTypeSystem 您应该将其替换为 self.yourButton = [UIButton buttonWithType:UIButtonTypeCustom]; 这将放弃您获得的有色选择选项。然后你可以改变它的状态图像如下:

[self.yourButton setBackgroundImage:[UIImage imageNamed:@"unselectedImage.png"] forState:UIControlStateNormal];
[self.yourButton setBackgroundImage:[UIImage imageNamed:@"selectedImage.png"] forState:UIControlStateSelected];

现在色调不会显示,您选择/未选择的图像将保留该图像,直到您再次改变状态

关于ios - UIButton 色调颜色影响处于选中状态的按钮的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28395050/

相关文章:

android - Swift 到 Kotlin : Struct to Data Class Example

javascript - iOS 上的 UIWebView 是否有向 DOM 添加接口(interface)的方法?

iphone - 如何在iphone中通过代码识别人声?

ios - UIButton 动画被跳过

ios - 如何防止 iOS 中同一个 UIButton 发生多个事件?

ios - 当快速触摸按钮外部时,突出显示继续

iphone - 如何实现像evernote-iphone一样的编辑

ios - Apple IAP 收据验证返回代码 21002

ios - 无法弄清楚雅虎天气应用程序中使用的 uiview 转换

iphone - 我可以完全删除 xib 文件吗?