TextField的使用

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

猜你喜欢

转载自blog.csdn.net/weixin_39013710/article/details/83148746