iOS開發之實時監測textField輸入變化
阿新 • • 發佈:2019-02-03
// 我這裡控制的是輸入使用者名稱和密碼長度控制,通過這個來設定登入按鈕能不能點選
[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;
}
}
}