输入框UITextField禁止输入空格

xiaoxiao2021-02-28  92

1,遵循UITextField的代理方法 2,实现代理方法

- (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; }
转载请注明原文地址: https://www.6miu.com/read-36274.html

最新回复(0)