IOS--常用控件--UITextField
2015-02-05 14:51 doudo 阅读(134) 评论(0) 编辑 收藏 举报1.控制输入的长度(此方法同时可以控制复制粘贴)
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString *string0 = [textField.text stringByReplacingCharactersInRange:range withString:string];
NSLog(@"%@",string0);
if (string0.length>15) {
textField.text=[string0 substringToIndex:15];
[[ZCYAlertView defaultAlert] promptMessage:@"名字已经很长了哦!" atDuration:2];
return NO;
}
else
return YES;
}