ios - 修改覆盖属性 willSet get/set 的值

标签 ios swift

我有一个自定义的 UILabel 并且我覆盖了它的文本属性。如果 upperCase = true,我需要修改此属性的值,问题是我正在递归调用 setter。

@IBDesignable class CustomLabel: UILabel {
@IBInspectable var upperCase: Bool = false
override var text: String? {
    willSet {
        if upperCase == true {
            text = newValue?.uppercaseString  
        }
    }
}
}

我也试过:

var aux: String?
override var text: String? {
    get { return aux }
    set {  aux = newValue }
}

但是没有设置文本标签。有什么建议吗?

最佳答案

使用 super

override var text: String? {
    get { return super.text }
    set(v){  super.text = v }
}

关于ios - 修改覆盖属性 willSet get/set 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32353506/

相关文章:

ios - Metal 中的多个 MTLDevice 实例

iOS Webrtc - 捕获本地视频流时崩溃

ios - Swift 泛型 : function with T. 类型作为参数返回可选 T

iOS swift : CIDetectorTypeRectangle is not convertible

iOS 图表 : Select the data point programmatically but get the highLight is NAN

ios - Unity转Xcode错误: Apple Mach-O Linker (ld) Error Group

ios - 移除时反转 CABasicAnimation

iphone - 图像应该遵循 iphone 中以前的触摸点?

ios - 暂停和恢复 for 循环

json - 如何将服务器数据传递/解析到 WatchKit 表行中的对象?