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

UITextField限制个数,没用代理

2016-06-12 14:00 387 查看
 _textField = [[UITextField
alloc]initWithFrame:CGRectMake(15,
10,
SCREENWIDTH-30,
50)];

    _textField.placeholder =
@"美食宣言";

    _textField.font = [UIFont
systemFontOfSize:13];

    _textField.autocorrectionType =
UITextAutocorrectionTypeNo;

    _textField.clearButtonMode =
UITextFieldViewModeWhileEditing;

    [_textField
addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];

    [self.view
addSubview:_textField];

- (void)textFieldDidChange:(UITextField *)textField

{

    if (textField.text.length >
99) {

        textField.text = [textField.text
substringToIndex:99];

        UIAlertView *aler=[[UIAlertView
alloc]initWithTitle:@"提醒"
message:@"最多可输入99字"
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:
nil];

        [aler show];

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: