美文网首页
iOS文本框 UITextField 文本框内设置不能输入空格

iOS文本框 UITextField 文本框内设置不能输入空格

作者: panda_熊猫 | 来源:发表于2017-09-23 10:15 被阅读40次

1.首先先遵循UITextField 的代理方法

UITextFieldDelegate

2.实现代理方法

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

//

NSString *tem = [[string componentsSeparatedByCharactersInSet:[NSCharacterSe whitespaceCharacterSet]]componentsJoinedByString:@""];

if (![string isEqualToString:tem]) {

return NO;

}

returnYES;

}

3.该方法可以活用 ,如输入的个数限制、只允许输入英文,这些限制都可以用该方法

只不过里面的方法变一下,最后return

相关文章

网友评论

      本文标题:iOS文本框 UITextField 文本框内设置不能输入空格

      本文链接:https://www.haomeiwen.com/subject/fucosxtx.html