【发布时间】:2016-05-10 21:41:04
【问题描述】:
如何为UITextView 设置UILabel 上剩余的字符?
我已经为UITextField 做了这个,但是同样的代码不起作用..
这是我尝试过的:
func textView(textView: UITextView, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool
{
if string == ""
{
if plainTextView.text!.characters.count == 0
{
charCount = 0
countLabel.text = String(format: "%i Characters Left", maxLength - charCount)
return false
}
charCount = (plainTextView.text!.characters.count - 1)
countLabel.text = String(format: "%i Characters Left", maxLength - charCount)
return true
}
else
{
charCount = (plainTextView.text!.characters.count + 1)
countLabel.text = String(format: "%i Characters Left", maxLength - charCount)
if charCount >= maxLength + 1
{
charCount = maxLength
countLabel.text = String(format: "%i Characters Left", maxLength - charCount)
return false;
}
}
return true
}
有什么建议吗?
【问题讨论】:
-
请提供您尝试过的代码
-
@user4261201 - 更新问题。
-
你的最大字符数限制是多少..
-
@Anbu.Karthik 最大字符数限制为 200。
标签: ios swift uitextview uitextviewdelegate