1设置textField文字字数和格式限制spa
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{orm
NSInteger existedLength = textField.text.length;string
NSInteger selectedLength = range.length;it
NSInteger replaceLength = string.length;select
if (existedLength - selectedLength + replaceLength < 7) {im
if ([string length]>0)数据
{margin
unichar single=[string characterAtIndex:0];//当前输入的字符top
if ((single >='0' && single<='9'))//数据格式正确di
{
return YES;
}else{
return NO;
}
}else{
return YES;
}
}else{
return NO;
}
}
2设置提示文字的大小,颜色
[textField setValue:[UIFont boldSystemFontOfSize:36] forKeyPath:@"_placeholderLabel.font"];
[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];