我有一个继承自 UIButton
的自定义 class
。我想要完成的事情是根据按钮的启用状态(即启用或禁用)设置 tintColor
属性。
有什么办法可以实现吗?
这是我的课:
class ButtonsPostMenu: UIButton
{
override func awakeFromNib()
{
titleLabel?.font = UIFont(name: Font_AvenirNext_Medium, size: 14)
tintColor = UIColor.white
}
}
最佳答案
您可以覆盖 isEnabled 属性来实现这一点。 tintColor 将根据按钮的 isEnabled 状态自动更改:
class ButtonsPostMenu:UIButton {
//......
override var isEnabled: Bool {
didSet{
if self.isEnabled {
self.tintColor = UIColor.white
}
else{
self.tintColor = UIColor.gray
}
}
}
//......
}
关于ios - 禁用和启用状态的 UIButton tintColor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45834966/