2015-09-14 20 views
0

起初,我想作一個無限循環吧:如何使用可選的func textViewDidEndEditing(textView:UITextView)在輸入文本時更改文本?

while stringLength == textView.text.characters.count{ 
       text.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: nsString.rangeOfString("hello")) 
        text.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: NSMakeRange(0, stringLength)) 

然而有人指出,要我去改變TextView的進入將使用可選的FUNC textViewDidEndEditing(textView: UITextView)文本的最佳方式。

我查看了蘋果文檔,一些教程和一些谷歌搜索,但似乎沒有人告訴我該怎麼做,或者一般如何使用可選功能。

我不介意閱讀,所以如果有人想指向我正確的文檔,我會非常樂意看看它。我只是無法找到任何我自己。編碼非常新穎。

+0

如果你想使用NSAttributeString,我建議你使用這個庫https://github.com/lsolniczek/string-in-chain更簡單直觀。 –

回答

0

在你的類,你應該把它聲明:

class ViewController: UIViewController,UITextViewDelegate 

,並在viewDidLoad中()設置

self.textView.delegate = self 

這樣你可以用你的委託方法。

相關問題