ios - 无法更改不同状态的 UIbutton 图像

标签 ios swift uibutton uiimage state

我想针对不同的状态更改 UIButton 的图像。为此,我使用:

btn.setImage(UIImage(named: "blabla"), for .normal)

btn.setImage(UIImage(named: blabla2), for .disabled)

这只会让一些看起来变暗。

我做错了什么?我只想让不同状态下的按钮外观相同,怎么做?

(我的按钮类型 - .system)。

最佳答案

这对我有帮助(swift 3.0)

btn.setImage(UIImage(named:"yourFriend")?.withRenderingMode(.alwaysOriginal), for: .normal)

btn.setImage(UIImage(named:"yourFriend")?.withRenderingMode(.alwaysOriginal), for: .disabled)

关于ios - 无法更改不同状态的 UIbutton 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41012908/

相关文章:

ios - 按钮中的图像无法加载,我只得到一个蓝色方 block

ios - 使用 UIButton 停止 NSTimer

ios - 从集合中删除对象会使 CoreData 中的逆关系无效

ios - NSDateFormatterLongStyle 字符串到 NSDate

ios - Xcode 管理器图标显示空白

ios - 将数组中的项目添加到特定索引处的不同数组

ios - URLImage 永远不会在 SwiftUI 的 Widget 应用程序中加载图像

iphone - Swift Apple Pay 崩溃; PKPaymentAuthorizationViewController = 无

ios - UIButton 高度为 0 但标题仍然可见

ios - 没有更多上下文,表达类型不明确