Bol*_*ion 6 uibutton ios swift
我有一个class
继承自己的自定义UIButton
.我想要完成的事情是tintColor
根据按钮的启用状态(即启用或禁用)设置属性.
有没有办法实现这一目标?
这是我的班级:
class ButtonsPostMenu: UIButton
{
override func awakeFromNib()
{
titleLabel?.font = UIFont(name: Font_AvenirNext_Medium, size: 14)
tintColor = UIColor.white
}
}
Run Code Online (Sandbox Code Playgroud)
您可以覆盖isEnabled属性来实现该目的.tintColor将根据按钮的isEnabled状态自动更改:
class ButtonsPostMenu:UIButton {
//......
override var isEnabled: Bool {
didSet{
if self.isEnabled {
self.tintColor = UIColor.white
}
else{
self.tintColor = UIColor.gray
}
}
}
//......
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4294 次 |
最近记录: |