iOS开发之实时监测textField输入变化

// 我这里控制的是输入用户名和密码长度控制,通过这个来设置登录按钮能不能点击
[self.accountText addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
[self.passwordText addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
- (void)textFieldDidChange:(UITextField *)textField {
if (textField == self.accountText || textField == self.passwordText) {
if (self.accountText.text.length >= 11 && self.passwordText.text.length >= 6) {
_loginBtn.selected = YES;
} else {
_loginBtn.selected = NO;
}
}
}

你可能感兴趣的:(iOS开发,---,随笔篇)