iOS????????????????????????
???????????? ???????[ 2016/7/7 11:38:52 ] ??????????????? ????????
????????3??????????Ч??
???????????????棺
????1.У????????????
????- (BOOL)isValidateMobile:(NSString *)mobile
????{
????NSString *phoneRegex = @"^[1][3??4??5??8??7][0-9]{9}$";
????NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@"?? phoneRegex];
????return [phoneTest evaluateWithObject:mobile];
????}
????2.У???????????????????????????
????3.??????????????????????
????4.????????????????????????????????????????????????
??????????????
????????????????????xib?????????棬??????KVC
????[_phone addTarget:self action:@selector(changePhone) forControlEvents:UIControlEventEditingChanged];
????[_password addTarget:self action:@selector(changeAction) forControlEvents:UIControlEventEditingChanged];
????[_email addTarget:self action:@selector(changeAction) forControlEvents:UIControlEventEditingChanged];
????[_loginButton setEnabled:NO];
????[_loginButton addTarget:self action:@selector(loginButtonAction) forControlEvents:UIControlEventTouchUpInside];
????????????
????????????????????
- (void)changePhone {
if (_phone.text.length >= 11) {
if ([self isValidateMobile:_phone.text]) {
_phone.textColor = [UIColor blackColor];
[_password becomeFirstResponder];
} else {
_phone.textColor = [UIColor redColor];
}
} else {
_phone.textColor = [UIColor blackColor];
}
}
???????????textfield??????????
- (void)changeAction {
if ((_password.text.length >= 1 && _phone.text.length >= 11 && _email.text.length >= 1) && [self isValidateMobile:_phone.text]) {
// ????????????? enable ???????userInteractionEnabled ???????дsetEnabled????????????????????Ч??
[_loginButton setEnabled:YES];
} else {
[_loginButton setEnabled:NO];
}
}
?????????????????????????????????????????????????????????????????????????????????????д???UIButton????????????????????????????Ч??
// .h
#import <UIKit/UIKit.h>
@interface UIButton (enable)
@end
// .m
#import "UIButton+enable.h"
@implementation UIButton (enable)
- (void)setEnabled:(BOOL)enabled {
[super setEnabled:enabled];
if (enabled) {
self.alpha = 1.0;
} else {
self.alpha = 0.5;
}
}
@end
??????????????????????????????д??????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11