首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

UITextField限制字符篇幅

2012-07-26 
UITextField限制字符字数?? ??[self.username_tf addTarget:self action:@selector(textEditingChanged:)

UITextField限制字符字数

?

? ??[self.username_tf addTarget:self action:@selector(textEditingChanged:) forControlEvents:UIControlEventEditingChanged];

? ? [self.password_tf addTarget:self action:@selector(textEditingChanged:) forControlEvents:UIControlEventEditingChanged];

?

?

?

?

?

?

-(void)textEditingChanged:(UITextField *)textField

{

? ? if (textField == self.username_tf) {

? ? ? ? if ([textField.text length]>20) {

? ? ? ? ? ? textField.text=[textField.text substringToIndex:20];

?

? ? ? ? ? ? //?[iToast makeText:@"用户名长度不应该超过20个字符"];

? ? ? ? }?

? ? }else if (textField == self.password_tf||textField == self.repassword_tf) {

? ? ? ? if ([textField.text length]>15) {

? ? ? ? ? ? textField.text=[textField.text substringToIndex:15];

? ? ? ? }?

? ? }

?

?

}

热点排行