标签:dex com bst lse 输入 设置 长度 objc range
设置 delegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField == self.liveThemeTextField) {
//这里的if时候为了获取删除操作,如果没有次if会造成当达到字数限制后删除键也不能使用的后果.
if (range.length == 1 && string.length == 0) {
return YES;
}
//so easy
else if (self.liveThemeTextField.text.length >= 30) {
self.liveThemeTextField.text = [textField.text substringToIndex:30];
return NO;
}
}
return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString *tem = [[string componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]componentsJoinedByString:@""];
if (![string isEqualToString:tem]) {
return NO;
}
return YES;
}
标签:dex com bst lse 输入 设置 长度 objc range
原文地址:https://www.cnblogs.com/sunmair/p/10294879.html