首页 > 代码库 > UITextField输入长度限制

UITextField输入长度限制

[_yourTextField addTarget:self action:@selector(eventEditingChange:) forControlEvents:UIControlEventEditingChanged];-(void)eventEditingChange:(UITextField *)sender {    UITextRange *markRange = sender.markedTextRange;    int pos = [sender offsetFromPosition:markRange.start    toPosition:markRange.end];    int nLength = sender.text.length - pos;    if (nLength > 20 && pos == 0)    sender.text = [sender.text substringToIndex:20];}

 

UITextField输入长度限制