iOS UITextField 小写字母自动显示大写
2016-05-02 本文已影响2691人
Misaki_yuyi
、、、
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if ([FunctionClass IsBlankString:string])
{
return YES;
}
char commitChar = [string characterAtIndex:0];
if (commitChar > 96 && commitChar < 123)
{
//小写变成大写
NSString * uppercaseString = string.uppercaseString;
NSString * str1 = [textField.text substringToIndex:range.location];
NSString * str2 = [textField.text substringFromIndex:range.location];
textField.text = [NSString stringWithFormat:@"%@%@%@",str1,uppercaseString,str2];
return NO;
}
return YES;
}
、、、