我在想是否可以将 didSet
用于属性内的属性。
假设我有一个函数 resize()
每次 UILabel
的 text
属性设置为新值(value)。我尝试使用标签自己的 didSet
,但它并没有像我预期的那样起作用。有没有办法做到这一点?
最佳答案
it didn't work, as I was expecting
你这是什么意思? didSet
适用于覆盖的属性。试试这个:
class MyLabel : UILabel {
override var text : String? {
didSet {
resize()
}
}
private func resize() {
print("text is now \(text). resizing...")
frame = CGRectMake(...
}
}
关于ios - 观察属性内部属性的变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33892094/