我有一个习惯class
继承自UIButton
。我想要完成的事情是设置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
}
}
}
//......
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)