- 對 UITextField進行內(nèi)容判斷
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 代表不全為數(shù)字
}else {
// 1 代表輸入的全為數(shù)字
}
- 修改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輸入位數(shù)(例如以下,最多輸入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;
}
最后編輯于 :
©著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。