【发布时间】:2017-01-18 06:42:42
【问题描述】:
我无法让我的 UILabel 通过更改其 textColor 来对我的 UITextView 做出反应。
所以当我的 UITextView 中有超过 250 个单词时,我的 UILabel 应该会变成红色。但是由于某种原因它没有这样做。
// class NewAppViewController: UIViewController, UITextViewDelegate...
func textViewDidChange(_ textView: UITextView) {
let characterCounts = commentTextField.text.characters.count
wordCountLabel.text = String(250 - characterCounts)
if (250 - characterCounts) < 0 {
self.wordCountLabel.textColor = UIColor.red
sendButton.isEnabled = false
} else {
sendButton.isEnabled = true
}
}
【问题讨论】:
-
您是否为 uitextview 指定了委托?
-
我想我找到了答案……
-
您一定错过了添加代理。
标签: ios swift uitextview uipopovercontroller uitextviewdelegate