第一种是给textField添加Target
账号密码的的textField
[user addTarget:self action:@selector(textValueChanged) forControlEvents:UIControlEventEditingChanged];
[pwd addTarget:self action:@selector(textValueChanged) forControlEvents:UIControlEventEditingChanged];
给这个添加方法 根据输入的账号和密码的都不为空时候 button开个变化
-(void)textValueChanged{
if (user.text.length != 0 && pwd.text.length != 0) {
[_landBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_landBtn.backgroundColor = DEF_RGB_COLOR(30 , 144, 255);
}else{
[_landBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
_landBtn.backgroundColor = [UIColor lightGrayColor];
}
}
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
- if (textField == _rightNameTextFeild)
- {
- NSInteger length = _rightNameTextFeild.text.length;
- NSInteger location = range.location;
- if ( length > location )
- {
- _landBtn.backgroundColor = [CHUtil colorWithHexString:@"d6d7d9"];
- }
- else
- {
- length += string.length;
- _landBtn.backgroundColor = [CHUtil colorWithHexString:@"fa4a26"];
- }
- }
- return YES;
- }