首页 > 学院 > 开发设计 > 正文

UITextfield限制文本位数的用法

2019-11-06 10:01:42
字体:
来源:转载
供稿:网友

UITextfield有这样一个属性markedTextRange: 英文解释: Discussion If there is no marked text, the value of the PRoperty is nil. Marked text is provisionally inserted text that requires user confirmation; it occurs in multistage text input. The current selection, which can be a caret or an extended range, always occurs within the marked text. 翻译: 如果没有标记的文本,属性的值为nil。标记文本是需要用户确认的临时插入文本; 它出现在多级文本输入中。当前选择(可以是插入符号或扩展范围)始终位于标记的文本中。 注释:所谓的标记文本指的是下图,并且在英文状态下markedTextRange为nil。 这里写图片描述 我们只需要在UITextFieldTextDidChangeNotification之后,做文本截取即可。 self.myTF.text = [self.myTF.text substringToIndex:MAX_LENGTH];


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表