Detect UILabel text change in swift

前端 未结 5 887
情书的邮戳
情书的邮戳 2020-12-25 15:28

Is there a way to get notified when there is a change in a UILabel\'s text or would I be better off using a UITextField with userInteractionE

5条回答
  •  被撕碎了的回忆
    2020-12-25 15:40

    Create a class that inherits from UILabel. Such as:

    class YourLabel: UILabel {
    
        override var text: String? {
            didSet {
                if let text = text {
                    println("Text changed.")
                } else {
                    println("Text not changed.")
                }
            }
        }
    }
    

    Create a outlet of this class for your object.

    @IBOutlet weak var label: YourLabel!
    label.text = "abc"
    

提交回复
热议问题