textfield在实际开发中用到的代理方法

来源:互联网 发布:windows 虚拟桌面软件 编辑:程序博客网 时间:2024/04/20 12:43
#pragma mark - UItextFieldDelegate


//点空白收键盘
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];

}


//点done收键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;

}


//实时监测textfield中的内容 当输入的内容是一个手机号后 将发送验证码button的颜色变红
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

    NSString *str1 = [NSString stringWithFormat:@"%@%@",textField.text,string];//str1:手机号
    if([str1 isMobilePhoneNumber])
    {
        buttonCode_.backgroundColor = DCOLOR_RED_5_0;
    }else{
        
    }
    return YES;
}
0 0
原创粉丝点击