1.TextField限制輸入位數方法
(1)數字鍵盤輸入時 (如果單純的根據字數判斷,會出現删除按鈕不能用的問題)
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
WinLoginCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
if (textField == cell.usernameTF) {
if (string.length == 0) return YES;
NSMutableString *newtxt = [NSMutableString stringWithString:textField.text];
[newtxt replaceCharactersInRange:range withString:string];
if (newtxt.length > 11) return NO;
}
return YES;
}
(2)其他鍵盤輸入
因為有拼音和聯想輸入,導緻上面的輸入會有漏洞
檢視:https://blog.csdn.net/blackwolfsky/article/details/51264060