简体   繁体   中英

.addTarget method to add an action to a UITextView

I have a function which detects change in a UITextView and changes the colour of a few words while the user is editing. Well, to link this function to a UITextField I can simply call the .addTarget method. But this does not work for the UITextView . I wanted to ask how I should connect the UITextView to the function. Thanks in advance.

Basically add "UITextViewDelegate" and do this

override func viewDidLoad() {
    yourTextView.delegate = self

}


func textViewDidChange(textView: UITextView) {
    //Whatever your code is
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM