iOS textField文字輸入字數以及格式限制

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"];  

相關文章
相關標籤/搜索