标签:tco 长度 ext led reserve 银行 inf cin hang
今天遇到一个需求,就是在绑卡的时候,要求输入姓名,证件号,银行卡号等信息,并且,如果这些TextFild只要有一个有值,那么绑定的这个按钮就要变为可点击状态,否则按钮不可点击。
当然了,我们还是根本TextField的delegate来实现
下面请看代码
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString *getString = [textField.text stringByReplacingCharactersInRange:range withString:string];/*textField输入的实时的值*/
NSString *realGetString = self.realNameTextField.text ; /*保存姓名的值*/
NSString *certificateNumGetString = self.certificateNumTextField.text ;
NSString *bankNumGetString = self.bankNumTextField.text ;
NSString *reservedPhoneGetString = self.reservedPhoneTextField.text ;
if (self.userName) // 这是用来验证是否是首次绑定(当前不是)
{
if([textField isEqual:self.bankNumTextField]) // 此时的textField是否是银行卡号的textField
{
bankNumGetString = getString;
}
else if([textField isEqual:self.reservedPhoneTextField])
{
reservedPhoneGetString = getString;
}
if (bankNumGetString.length == 0 && reservedPhoneGetString.length == 0)
{ // 如果银行卡号和银行预留号码的长度为0,按钮不可点击
[_bindButton setTitleColor:[UIColor hexFloatColor:@"c9c9c9"] forState:UIControlStateNormal];
_bindButton.userInteractionEnabled = NO;
}
else
{
[_bindButton setTitleColor:[UIColor hexFloatColor:InfoLabelHightLightColor] forState:UIControlStateNormal];
_bindButton.userInteractionEnabled = YES;
}
}
else
{
if([textField isEqual:self.realNameTextField])
{
realGetString = getString;
}
else if([textField isEqual:self.certificateNumTextField])
{
certificateNumGetString = getString;
}
else if([textField isEqual:self.bankNumTextField])
{
bankNumGetString = getString;
}
else if([textField isEqual:self.reservedPhoneTextField])
{
reservedPhoneGetString = getString;
}
if (realGetString.length == 0 && certificateNumGetString.length == 0 && bankNumGetString.length == 0 && reservedPhoneGetString.length == 0)
{
[_bindButton setTitleColor:[UIColor hexFloatColor:@"c9c9c9"] forState:UIControlStateNormal];
_bindButton.userInteractionEnabled = NO;
}
else
{
[_bindButton setTitleColor:[UIColor hexFloatColor:InfoLabelHightLightColor] forState:UIControlStateNormal];
_bindButton.userInteractionEnabled = YES;
}
}
return YES;
}
标签:tco 长度 ext led reserve 银行 inf cin hang
原文地址:http://www.cnblogs.com/huiyi-520/p/7687911.html