iOS 限制TextField输入长度(支持删除)

if (textField == _phoneTF) {
        
         //支持删除
         if (range.length == 1 && string.length == 0) {
             return YES;
         }
         
         else if (_phoneTF.text.length >= 11) {
             
             _phoneTF.text = [textField.text substringToIndex:11];
             
             //提示:可以去掉
        [NDHudView showText:
@"联系方式不得超过11位!" animated:YES configParameter:^(NDHudView *config) { } duration:1.0 inView:[AppDelegate sharedInstance].window]; return NO; } else{ return YES; } }
原文地址:https://www.cnblogs.com/jukaiit/p/9269436.html