- 对 UITextField进行内容判断
NSScanner* scan = [NSScanner scannerWithString:self.countTextField.text];
int val;
NSString *string = [NSString stringWithFormat:@"%d",[scan scanInt:&val] && [scan isAtEnd]];
NSLog(@"%d",[scan scanInt:&val] && [scan isAtEnd]);
if ([string isEqualToString:@"0"]) {
// 0 代表不全为数字
}else {
// 1 代表输入的全为数字
}
- 修改UITextField中placeholder的字体颜色
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[NSForegroundColorAttributeName] =Color(201,197,189);
NSAttributedString *attribute = [[NSAttributedString alloc]initWithString:self.emailText.placeholder attributes:dict];
[self.emailText setAttributedPlaceholder:attribute];
- textField 不顶格输入
tel.leftView = [[UIView alloc]initWithFrame:CGRectMake(0,0,8,0)];
tel.leftViewMode =UITextFieldViewModeAlways;
- textField 密文输入
password.secureTextEntry =YES;
- 限制texfield输入位数(例如以下,最多输入4位)
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (textField == self.authorizationPassword) {
if (string.length == 0) return YES;
NSInteger existedLength = textField.text.length;
NSInteger selectedLength = range.length;
NSInteger replaceLength = string.length;
if (existedLength - selectedLength + replaceLength > 4) {
return NO;
}
}
return YES;
}