您的位置:首页 > 产品设计 > UI/UE

UITextField,UITextView字数限制

2013-12-16 13:53 337 查看
UITextField,UITextView字数限制

主要是使用他们的两个代理方法

//标题限制在 30个字以内

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (range.location>=30)
{
UIAlertView *alertNums = [[UIAlertView alloc]initWithTitle:@"输入提示" message:@"标题字数限制在30字以内!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alertNums show];
return  NO;
}
else
{
return YES;
}

}
//内容限制在100个字以内;

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if (range.location>=100)
{
UIAlertView *alertNums = [[UIAlertView alloc]initWithTitle:@"输入提示" message:@"内容限制在100字以内!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alertNums show];
return  NO;
}
else
{
return YES;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: