UITextField inherits from UIControl and has the related characteristics and methods of UIControl.
UITextField is a control used to accept user input. It can be created through code, xib, and storyboard. It has corresponding proxy methods:
- (void)viewDidLoad {
[super viewDidLoad];
self.accountTextF.delegate = self;
[self.accountTextF addTarget:self action:@selector(textChanged) forControlEvents:UIControlEventEditingChanged];
self.passWordTF.delegate = self;
[self.passWordTF addTarget:self action:@selector(textChanged) forControlEvents:UIControlEventEditingChanged];
}
#pragma mark - 监测tf输入编辑事件
- (void)textChanged{
if (self.accountTextF.text.length > 0 && self.passWordTF.text.length > 0) {
self.loginButton.enabled = YES;
}else{
self.loginButton.enabled = NO;
}
}
#pragma mark - TextFild delegate function
// 是否开始进入编辑状态
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
return YES;
}
// 是否结束编辑状态
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
return YES;
}
// 是否改变编辑的字符串(可用于判断是否允许输入)
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
return YES;
}
// 是否清除
- (BOOL)textFieldShouldClear:(UITextField *)textField{
return YES;
}
// 结束编辑时调用
- (void)textFieldDidEndEditing:(UITextField *)textField{
}
// 开始编辑时调用
- (void)textFieldDidBeginEditing:(UITextField *)textField{
}