ios - UIButton 属性观察者 didset 从未调用过
问题描述
我在 cocoapods 库中有一个简单的按钮,当它被调用时我需要更改 tintcolorisHighlighted
但是 isHighlighted 被调用但 didset 或 willset 永远不会被调用。
我当然将我的按钮设置为突出显示,并且在我将 tableview 单元格出列后调用此函数
func setupCell() {
let myCustomButton = UIButton.button(title: "Button")
myCustomButton.isHighlighted = true
}
我的 UIButton 扩展
extension UIButton {
public static func button(title: String) -> UIButton {
let button = UIButton(type: .custom)
button.setTitle(title, for: .normal)
button.setTitleColor(UIColor.gray, for: .normal)
return button
}
override open var isHighlighted: Bool {
didSet {
print("Never gets here, ever!")
}
}
}
如何触发 didSet?除了将 isHighlighted 设置为 true 之外,还有其他方法吗?
解决方案
推荐阅读
- css - React:动画三元输出组件
- swiftui - SwiftUI 本地化
- android - 防止数字在语言环境更新的 android 上从英语更改为阿拉伯语
- c - /proc/id/maps 中堆栈附近的堆
- python - 如何恢复到 python 2.7?
- ios - Info.plist 未复制到 DerivedData 导致 Xcode 中的编译错误
- amazon-web-services - 适用于 EC2、EMR、Redshift、RDS 的 AWS 开发工具包用例
- java - 面对 java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
- go - 即使我得到一个着色器编译错误,所有着色器都可以正常工作。如何?
- css - 带有重复修饰符的 CSS 后代选择