Commit ac847042 by ludi

完成登录页改造

parent 5a92caa7
Showing with 462 additions and 61 deletions
......@@ -95,4 +95,12 @@ NS_ASSUME_NONNULL_BEGIN
@end
@interface NSString (FUSLocalization)
+(NSString *)fus_versionLocalString:(NSString *)key;
+(NSString *)fus_localString:(NSString *)key;
@end
NS_ASSUME_NONNULL_END
......@@ -299,3 +299,16 @@ static NSString *const FUSArbicLangArea = @"1001";
}
@end
@implementation NSString (FUSLocalization)
+ (NSString *)fus_versionLocalString:(NSString *)key{
return FUSLocalizationHelper.versionLocalString(key);
}
+ (NSString *)fus_localString:(NSString *)key{
return FUSLocalizationHelper.localString(key);
}
@end
......@@ -15,6 +15,11 @@ typedef enum {
dismissViewController,
}BackFunction;
typedef NS_ENUM(NSUInteger, FUSNavigationBackBtnStyle) {
FUSNavigationBackBtnStyleBlack,
FUSNavigationBackBtnStyleWhite,
};
@interface FUSBaseViewController : UIViewController
// 获取用户ID
......@@ -30,6 +35,9 @@ typedef enum {
// 是否隐藏网页导航栏右上角的按钮
@property (nonatomic, assign) BOOL hiddenNavRightBtns;
/// 返回按钮样式
@property (nonatomic, assign) FUSNavigationBackBtnStyle backBtnStyle;
// 左上角放回按钮
@property (nonatomic, copy) void(^onClickBackHandle)(void);
......
......@@ -21,6 +21,8 @@
// loading的动效
@property (nonatomic, strong) FUSFuSiLoadingView *loadingView;
/// 返回的按钮
@property (nonatomic, strong) FUSButton *backButton;
@end
......@@ -101,6 +103,7 @@
// 设置默认视图底色
self.view.backgroundColor = UIColor.fus_appBGColor;
self.backBtnStyle = FUSNavigationBackBtnStyleBlack;
// 初始化导航栏
[self initBaseNavigation];
......@@ -189,7 +192,12 @@
_animated = animated;
FUSButton *backButton = [[FUSButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44)];
[backButton setImage:UIImage.fus_backImage forState:UIControlStateNormal];
UIImage *backImg = UIImage.fus_backImage;
if (self.backBtnStyle == FUSNavigationBackBtnStyleWhite) {
backImg = UIImage.fus_backWhiteImage;
}
[backButton setImage:backImg forState:UIControlStateNormal];
backButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
if (popVC == popViewController) {
......@@ -199,7 +207,24 @@
} else if (popVC == dismissViewController) {
[backButton addTarget:self action:@selector(dismissVC) forControlEvents:UIControlEventTouchUpInside];
}
self.backButton = backButton;
}
- (void)setBackBtnStyle:(FUSNavigationBackBtnStyle)backBtnStyle{
_backBtnStyle = backBtnStyle;
if (!self.backButton) {
return;
}
switch (backBtnStyle) {
case FUSNavigationBackBtnStyleBlack:
[self.backButton setImage:UIImage.fus_backImage forState:UIControlStateNormal];
break;
case FUSNavigationBackBtnStyleWhite:
[self.backButton setImage:UIImage.fus_backWhiteImage forState:UIControlStateNormal];
break;
default:
break;
}
}
- (void)popViewController
......
......@@ -16,8 +16,20 @@ typedef enum :NSInteger{
FUSInputTypeExceptChineseCharacter, //除了汉字以外
}FUSTextFieldInputType;
@protocol FUSTextFieldDelegate <NSObject>
@optional
/// 监听回删方法
-(void)fus_textFieldWillDeleteBackward:(UITextField *)textField;
-(void)fus_textFieldDidDeleteBackward:(UITextField *)textField;
@end
@interface FUSTextField : UITextField
@property (nonatomic, weak) id<FUSTextFieldDelegate> fus_delegate;
//!< 扩展UITextField的内边距属性,默认都为2
@property(nonatomic) UIEdgeInsets contentEdgeInsets;
......@@ -56,6 +68,16 @@ typedef enum :NSInteger{
@property (nonatomic, assign) BOOL shouldSelectAll;
/// 是否只是用于显示(禁用粘贴、选择和全选功能)
@property (nonatomic, assign) BOOL displayOnly;
/// 如果设定了这个,那么清除按钮就跟随这个颜色
@property (nonatomic, strong) UIColor *clearButtonColor;
/// 如果设定了这个image,那么清除按钮就跟随这个,如果没设置,就跟随calearButtonColor
@property (nonatomic, strong) UIImage *clearButtonImage;
/**
* 文本改变更新
*/
......
......@@ -50,6 +50,7 @@
self.shouldSelectAll = YES;
self.shouldPaste = YES;
self.checkChineseLen = YES;
self.displayOnly = NO;
}
return self;
}
......@@ -62,6 +63,7 @@
self.shouldCopy = YES;
self.shouldSelectAll = YES;
self.shouldPaste = YES;
self.displayOnly = NO;
[UITextField yz_hookTextField];
self.inputType = FUSInputTypeAllCharacters;
self.delegate = self;
......@@ -71,6 +73,54 @@
return self;
}
- (void)layoutSubviews{
[super layoutSubviews];
if (self.clearButtonColor != nil || self.clearButtonImage != nil) {
[self tintClearImage];
}
}
#pragma mark --- 设置清除按钮
-(void)tintClearImage{
for (UIView *view in self.subviews) {
if ([view isKindOfClass:[UIButton class]]) {
UIButton *btn = (UIButton *)view;
UIImage *image = [btn imageForState:UIControlStateHighlighted];
if (image != nil) {
if (self.clearButtonImage == nil) {
if (self.clearButtonColor != nil) {
self.clearButtonImage = [self tintImage:image withColor:self.clearButtonColor];
}else {
self.clearButtonImage = [self tintImage:image withColor:self.tintColor];
}
}
[btn setImage:self.clearButtonImage forState:UIControlStateNormal];
[btn setImage:self.clearButtonImage forState:UIControlStateHighlighted];
}
}
}
}
- (UIImage *)tintImage:(UIImage *)image withColor:(UIColor *)color {
CGSize size = image.size;
UIGraphicsBeginImageContextWithOptions(size, NO, image.scale);
CGContextRef context = UIGraphicsGetCurrentContext();
[image drawAtPoint:CGPointZero blendMode:kCGBlendModeNormal alpha:1.0];
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextSetBlendMode(context, kCGBlendModeSourceIn);
CGContextSetAlpha(context, 1.0);
CGRect rect = CGRectMake(CGPointZero.x, CGPointZero.y, image.size.width, image.size.height);
CGContextFillRect(context, rect);
UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return tintedImage ?: [UIImage new];
}
#pragma mark —- 扩展UITextField获取长度
// 获取文本长度
......@@ -340,6 +390,11 @@ static const int cursorLength = 30; //!< 定义光标长度
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (self.displayOnly) {
return NO;
}
if (action == @selector(paste:)) {
// 复制
if (self.shouldPaste) {
......@@ -371,6 +426,16 @@ static const int cursorLength = 30; //!< 定义光标长度
return [super canPerformAction:action withSender:sender];
}
- (void)deleteBackward{
if (self.fus_delegate && [self.fus_delegate respondsToSelector:@selector(fus_textFieldWillDeleteBackward:)]) {
[self.fus_delegate fus_textFieldWillDeleteBackward:self];
}
[super deleteBackward];
if (self.fus_delegate && [self.fus_delegate respondsToSelector:@selector(fus_textFieldDidDeleteBackward:)]) {
[self.fus_delegate fus_textFieldDidDeleteBackward:self];
}
}
/*
// Only override drawRect: if you perform custom drawing.
......
......@@ -20,6 +20,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (UIImage *)fus_backImage;
+(UIImage *)fus_backWhiteImage;
/// 默认头像
+ (UIImage *)fus_defaultIcon;
......
......@@ -67,6 +67,10 @@
return [self fus_ImageNamed:@"fus_common_navigation_back_black"];
}
+ (UIImage *)fus_backWhiteImage{
return [self fus_ImageNamed:[FUSRTL RTLImageName:@"common_navigation_back_white"]];
}
+ (UIImage *)fus_defaultIcon {
return [self fus_ImageNamed:@"icon_boy_default"];
}
......
......@@ -28,6 +28,8 @@
+(UIColor *)fus_inpuContentColor;
/// 主题色
+(UIColor *)fus_themeColor;
/// 第三主题色,蓝色,一般用于验证码白底蓝色边框和字体
+(UIColor *)fus_themeThirdColor;
/// 钻石蓝色
+(UIColor *)fus_diamondBlue;
/// 泪水蓝
......@@ -45,6 +47,8 @@
+(UIColor *)fus_textColorLight;
/// 通用字体颜色,反色 fffff
+(UIColor *)fus_textColorVeryLight;
/// 输入框背景色,灰色
+(UIColor *)fus_textInputBackgroundGrayColor;
/// 弹窗背景颜色
+(UIColor *)fus_alertViewBackgroundColor;
......
......@@ -55,6 +55,10 @@
return [self fus_diamondBlue];
}
+ (UIColor *)fus_themeThirdColor{
return [UIColor colorWithHex:@"00a0e9"];
}
+(UIColor *)fus_diamondBlue{
return [UIColor colorWithHex:@"#01D9E0"];
}
......@@ -82,6 +86,9 @@
+ (UIColor *)fus_textColorVeryLight{
return [UIColor colorWithHex:@"#FFFFFF"];
}
+ (UIColor *)fus_textInputBackgroundGrayColor{
return [UIColor colorWithHex:@"#EFEFEF"];
}
+ (UIColor *)fus_alertViewBackgroundColor{
return [UIColor colorWithHex:@"#000000" alpha:0.6];
......
......@@ -167,6 +167,18 @@
//取出数据
_countryDic = [NSMutableDictionary dictionaryWithDictionary:[[FUSCountryHelper sharedInstance] fus_getAllCountries]];
// 过滤掉ban掉的国家
NSArray *banCountryNamesArr = [[FUSCountryHelper sharedInstance] getBanCountryNamesArr];
[_countryDic.allKeys enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSMutableArray *wordCountriesArr = [[NSMutableArray alloc] init];
for (NSDictionary *countryDict in _countryDic[obj]) {
if (![banCountryNamesArr containsObject:countryDict[@"en_ctr"]]) {
[wordCountriesArr addObject:countryDict];
}
}
_countryDic[obj] = wordCountriesArr;
}];
[_countryDic enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
NSMutableArray *models = [NSMutableArray array];
......
......@@ -21,7 +21,7 @@
#import "FUSDataStatisticsManager.h"
@interface FUSLoginPhoneViewController () <UITextFieldDelegate>
@interface FUSLoginPhoneViewController () <UITextFieldDelegate, FUSTextFieldDelegate>
@property (nonatomic ,copy) NSString *phone;
......@@ -51,7 +51,7 @@
/**
区号 Label
*/
@property (strong, nonatomic) IBOutlet UILabel *areaCodeLabel;
@property (weak, nonatomic) IBOutlet FUSTextField *areaCodeTextField;
@property (weak, nonatomic) IBOutlet UIView *areaBgView;
......@@ -87,7 +87,7 @@
// 初始化View
-(void)initView
{
_loginButton.style = FUSButtonStyleBlueBorder;
_loginButton.style = FUSButtonStyleBlue;
_loginButton.layer.cornerRadius = _loginButton.height/2.0;
_loginButton.clipsToBounds = YES;
_loginButton.enabled = NO;
......@@ -100,10 +100,15 @@
_phoneTextField.textMaxLength = 13;
_phoneTextField.inputType = FUSInputTypeNumber;
_phoneTextField.fus_delegate = self;
_phoneTextField.delegate = self;
[_phoneTextField addTarget:self action:@selector(textFiledEditChanged:) forControlEvents:UIControlEventEditingChanged];
[_phoneTextField addTarget:self action:@selector(textFieldDidBeginEditing:) forControlEvents:UIControlEventEditingDidBegin];
_areaCodeTextField.textMaxLength = 4;
_areaCodeTextField.displayOnly = YES;
[_areaCodeTextField addTarget:self action:@selector(textFiledEditChanged:) forControlEvents:UIControlEventEditingChanged];
self.countryInfoDict = [[NSUserDefaults standardUserDefaults] objectForKey:USER_COUNTRY_INFO];
if(!self.countryInfoDict){// 设置默认值
......@@ -131,6 +136,11 @@
[self fus_fitRTLView];
[self fus_setupLocalStrings];
[self fus_checkStateDidUpdate];
//fusi color
self.titleLabel.textColor = [UIColor fus_textColorRich];
_areaBgView.backgroundColor = [UIColor fus_textInputBackgroundGrayColor];
_teleBgView.backgroundColor = [UIColor fus_textInputBackgroundGrayColor];
}
- (void)fus_checkStateDidUpdate {
......@@ -160,9 +170,10 @@
- (void)fus_fitRTLView {
UIImage *backImage = [UIImage imageNamed:[FUSRTL RTLImageName:@"common_navigation_back_white"]];;
// UIImage *backImage = [UIImage imageNamed:[FUSRTL RTLImageName:@"common_navigation_back_white"]];
UIImage *backImage = [UIImage fus_backImage];
[self.backBtn setImage:backImage forState:UIControlStateNormal];
self.backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
// self.backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
UIImage *rightArrowImage = [[UIImage imageNamed:@"icon_right_arrows"] fusrtl_imageFlippedForRightToLeftLayoutDirection];
......@@ -201,6 +212,7 @@
// 隐藏键盘.
[_phoneTextField resignFirstResponder];
[_areaCodeTextField resignFirstResponder];
sender.userInteractionEnabled = NO;
[FUSLoadingView fus_showProgressViewWithMessage:nil];
......@@ -252,11 +264,35 @@
*/
-(void)textFiledEditChanged:(FUSTextField *)textField
{
if ([NSString isNull:_phoneTextField.text]) {
if ([NSString isNull:_phoneTextField.text] || [NSString isNullWithString:_areaCodeTextField.text]) {
self.loginButton.enabled = NO;
} else {
self.loginButton.enabled = YES;
}
if ([textField isEqual:_areaCodeTextField]) {
self.countryInfoDict = nil;
//地区编码选择
if (![NSString isNullWithString:_areaCodeTextField.text]) {
NSArray *resCountryInfoList = [[FUSCountryHelper sharedInstance] fus_getCountryInfoListForCountryCode:_areaCodeTextField.text];
for (NSDictionary *obj in resCountryInfoList) {
if ([obj[FUSCountryCodeKey] isEqualToString:_areaCodeTextField.text]) {
self.countryInfoDict = obj;
break;
}
}
// YALogDebug(@"%@",resCountryInfoList);
if (resCountryInfoList.count == 1 && self.countryInfoDict) {
//只有一个选项的时候,并且完全匹配,说明用户就是填的这个,那么光标就位移到点话号码那
[_phoneTextField becomeFirstResponder];
}
}
[self displayCountryNameAndCountryCode];
}
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
......@@ -270,6 +306,21 @@
return [textField validateInputString:string];
}
- (void)fus_textFieldWillDeleteBackward:(UITextField *)textField{
if (textField == _phoneTextField) {
// 检查删除动作,并且当前文本长度为0
if (textField.text.length == 0) {
// 将光标移到第一个 UITextField
[_areaCodeTextField becomeFirstResponder];
if (_areaCodeTextField.text.length > 0) {
_areaCodeTextField.text = [_areaCodeTextField.text substringToIndex:_areaCodeTextField.text.length - 1];
[self textFiledEditChanged:_areaCodeTextField];
}
}
}
}
/**
设置国家地区
*/
......@@ -302,33 +353,58 @@
*/
- (void)displayCountryNameAndCountryCode
{
if (!self.countryInfoDict) {
self.countryInfoDict = [[FUSCountryHelper sharedInstance] fus_getCountryInfoForCountryName:@"Taiwan"];
}
NSString *countryName = [_countryInfoDict objectForKey:FUSCountryLocaleNameKey];
NSString *countryCode = [_countryInfoDict objectForKey:FUSCountryCodeKey];
if ([NSString isNull:countryName]) {
self.countryInfoDict = [[FUSCountryHelper sharedInstance] fus_getCountryInfoForCountryCode:countryCode];
[self displayCountryNameAndCountryCode];
return;
}
if (self.countryInfoDict && ![NSString isNullWithString:[_countryInfoDict objectForKey:FUSCountryLocaleNameKey]]) {
self.countryLabel.text = countryName;
self.countryLabel.textAlignment = NSTextAlignmentRight;
[[NSUserDefaults standardUserDefaults] setObject:self.countryInfoDict forKey:USER_COUNTRY_INFO];
self.areaCodeLabel.text = [NSString stringWithFormat:@"+%@", countryCode];
NSInteger length = [[FUSCountryHelper sharedInstance] lengthForPhoneNumberWithCountryCode:countryCode];
if (length == 0) length = 13;
self.phoneTextField.textMaxLength = length;
if (![NSString isNull:self.phone]) {
self.phoneTextField.text = self.phone;
NSString *countryName = [_countryInfoDict objectForKey:FUSCountryLocaleNameKey];
NSString *countryCode = [_countryInfoDict objectForKey:FUSCountryCodeKey];
self.countryLabel.text = countryName;
self.countryLabel.textAlignment = NSTextAlignmentRight;
[NSUserDefaults.standardUserDefaults setValue:self.countryInfoDict forKey:USER_COUNTRY_INFO];
[NSUserDefaults.standardUserDefaults synchronize];
self.areaCodeTextField.text = countryCode;
NSInteger length = [[FUSCountryHelper sharedInstance] lengthForPhoneNumberWithCountryCode:countryCode];
if (length == 0) length = 13;
self.phoneTextField.textMaxLength = length;
}else {
self.countryInfoDict = nil;
self.countryLabel.text = [NSString fus_versionLocalString:@"未知国家"];
self.countryLabel.textAlignment = NSTextAlignmentRight;
}
// if (!self.countryInfoDict) {
//
// self.countryInfoDict = [[FUSCountryHelper sharedInstance] fus_getCountryInfoForCountryName:@"Taiwan"];
// }
//
// NSString *countryName = [_countryInfoDict objectForKey:FUSCountryLocaleNameKey];
// NSString *countryCode = [_countryInfoDict objectForKey:FUSCountryCodeKey];
//
// if ([NSString isNull:countryName]) {
// self.countryInfoDict = [[FUSCountryHelper sharedInstance] fus_getCountryInfoForCountryCode:countryCode];
// [self displayCountryNameAndCountryCode];
// return;
// }
//
//
// self.countryLabel.text = countryName;
// self.countryLabel.textAlignment = NSTextAlignmentRight;
// [[NSUserDefaults standardUserDefaults] setObject:self.countryInfoDict forKey:USER_COUNTRY_INFO];
// self.areaCodeLabel.text = [NSString stringWithFormat:@"+%@", countryCode];
//
// NSInteger length = [[FUSCountryHelper sharedInstance] lengthForPhoneNumberWithCountryCode:countryCode];
// if (length == 0) length = 13;
// self.phoneTextField.textMaxLength = length;
//
// if (![NSString isNull:self.phone]) {
// self.phoneTextField.text = self.phone;
// }
}
- (BOOL)isValidatePhoneNumber:(NSString *)number {
......
......@@ -22,7 +22,7 @@
#import "FUSStyleButton.h"
#import "FUSMainViewControllerHelper.h"
@interface FUSLoginViewController () <UITextFieldDelegate>
@interface FUSLoginViewController () <UITextFieldDelegate, FUSTextFieldDelegate>
@property (strong, nonatomic) IBOutlet UIButton *backBtn;
@property (strong, nonatomic) IBOutlet UIImageView *areaRightImageView;
......@@ -52,7 +52,7 @@
/**
区号 Label
*/
@property (strong, nonatomic) IBOutlet UILabel *areaCodeLabel;
@property (weak, nonatomic) IBOutlet FUSTextField *areaCodeTextField;
@property (weak, nonatomic) IBOutlet UIView *areaBgView;
......@@ -77,6 +77,12 @@
}else {
[_passwordTextField becomeFirstResponder];
}
//fusi 客制化颜色
self.titleLabel.textColor = [UIColor fus_textColorRich];
self.areaBgView.backgroundColor = [UIColor fus_textInputBackgroundGrayColor];
self.teleBgView.backgroundColor = [UIColor fus_textInputBackgroundGrayColor];
self.codeBgView.backgroundColor = [UIColor fus_textInputBackgroundGrayColor];
}
- (void)viewWillAppear:(BOOL)animated{
......@@ -98,7 +104,7 @@
// 初始化View
-(void)initView
{
_loginButton.style = FUSButtonStyleBlueBorder;
_loginButton.style = FUSButtonStyleBlue;
_loginButton.layer.cornerRadius = _loginButton.height/2.0;
_loginButton.clipsToBounds = YES;
_loginButton.enabled = NO;
......@@ -113,12 +119,18 @@
_passwordTextField.textMaxLength = 16;
_passwordTextField.inputType = FUSInputTypeAllCharacters;
_phoneTextField.delegate = self;
_phoneTextField.fus_delegate = self;
_passwordTextField.delegate = self;
[_phoneTextField addTarget:self action:@selector(textFiledEditChanged:) forControlEvents:UIControlEventEditingChanged];
[_passwordTextField addTarget:self action:@selector(textFiledEditChanged:) forControlEvents:UIControlEventEditingChanged];
[_phoneTextField addTarget:self action:@selector(textFieldDidBeginEditing:) forControlEvents:UIControlEventEditingDidBegin];
[_passwordTextField addTarget:self action:@selector(textFieldDidBeginEditing:) forControlEvents:UIControlEventValueChanged];
_areaCodeTextField.textMaxLength = 4;
_areaCodeTextField.displayOnly = YES;
[_areaCodeTextField addTarget:self action:@selector(textFiledEditChanged:) forControlEvents:UIControlEventEditingChanged];
// 自动填写账号、密码
FUSAccountModel *lastAccount = [[FUSAccountStore shareStore] lastAccount];
if ([NSObject isMobileNumberWithString:self.phone]) {
......@@ -213,9 +225,9 @@
- (void)fus_fitRTLView {
UIImage *backImage = [UIImage imageNamed:[FUSRTL RTLImageName:@"common_navigation_back_white"]];;
[self.backBtn setImage:backImage forState:UIControlStateNormal];
self.backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
// UIImage *backImage = [UIImage imageNamed:[FUSRTL RTLImageName:@"common_navigation_back_white"]];;
[self.backBtn setImage:[UIImage fus_backImage] forState:UIControlStateNormal];
// self.backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
UIImage *rightArrowImage = [[UIImage imageNamed:@"icon_right_arrows"] fusrtl_imageFlippedForRightToLeftLayoutDirection];
......@@ -265,6 +277,7 @@
// 隐藏键盘.
[_passwordTextField resignFirstResponder];
[_phoneTextField resignFirstResponder];
[_areaCodeTextField resignFirstResponder];
NSString *phone = [_phoneTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *pwd = [_passwordTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
......@@ -416,11 +429,36 @@
*/
-(void)textFiledEditChanged:(FUSTextField *)textField
{
if ([NSString isNull:_phoneTextField.text] || [NSString isNull:_passwordTextField.text] || !(_passwordTextField.text.length <= 16 && _passwordTextField.text.length >= 6)) {
if ([NSString isNull:_phoneTextField.text] || [NSString isNull:_passwordTextField.text] || !(_passwordTextField.text.length <= 16 && _passwordTextField.text.length >= 6) || [NSString isNullWithString:_areaCodeTextField.text]) {
[self setupLoginButtonEnable:NO];
} else {
[self setupLoginButtonEnable:YES];
}
// ludy:监听区号选择,当已经填到唯一区号后,立马显示
if ([textField isEqual:_areaCodeTextField]) {
self.countryInfoDict = nil;
//地区编码选择
if (![NSString isNullWithString:_areaCodeTextField.text]) {
NSArray *resCountryInfoList = [[FUSCountryHelper sharedInstance] fus_getCountryInfoListForCountryCode:_areaCodeTextField.text];
for (NSDictionary *obj in resCountryInfoList) {
if ([obj[FUSCountryCodeKey] isEqualToString:_areaCodeTextField.text]) {
self.countryInfoDict = obj;
break;
}
}
// YALogDebug(@"%@",resCountryInfoList);
if (resCountryInfoList.count == 1 && self.countryInfoDict) {
//只有一个选项的时候,并且完全匹配,说明用户就是填的这个,那么光标就位移到点话号码那
[_phoneTextField becomeFirstResponder];
}
}
[self displayCountryNameAndCountryCode];
}
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
......@@ -437,6 +475,22 @@
return [textField validateInputString:string];
}
- (void)fus_textFieldWillDeleteBackward:(UITextField *)textField{
if (textField == _phoneTextField) {
// 检查删除动作,并且当前文本长度为0
if (textField.text.length == 0) {
// 将光标移到第一个 UITextField
[_areaCodeTextField becomeFirstResponder];
if (_areaCodeTextField.text.length > 0) {
_areaCodeTextField.text = [_areaCodeTextField.text substringToIndex:_areaCodeTextField.text.length - 1];
[self textFiledEditChanged:_areaCodeTextField];
}
}
}
}
/**
设置国家地区
*/
......@@ -469,32 +523,55 @@
*/
- (void)displayCountryNameAndCountryCode
{
if (!self.countryInfoDict) {
self.countryInfoDict = [[FUSCountryHelper sharedInstance] fus_getCountryInfoForCountryName:@"Taiwan"];
}
NSString *countryName = [_countryInfoDict objectForKey:FUSCountryLocaleNameKey];
NSString *countryCode = [_countryInfoDict objectForKey:FUSCountryCodeKey];
if ([NSString isNull:countryName]) {
self.countryInfoDict = [[FUSCountryHelper sharedInstance] fus_getCountryInfoForCountryCode:countryCode];
[self displayCountryNameAndCountryCode];
return;
if (self.countryInfoDict && ![NSString isNullWithString:[_countryInfoDict objectForKey:FUSCountryLocaleNameKey]]) {
NSString *countryName = [_countryInfoDict objectForKey:FUSCountryLocaleNameKey];
NSString *countryCode = [_countryInfoDict objectForKey:FUSCountryCodeKey];
self.countryLabel.text = countryName;
self.countryLabel.textAlignment = NSTextAlignmentRight;
[NSUserDefaults.standardUserDefaults setValue:self.countryInfoDict forKey:USER_COUNTRY_INFO];
[NSUserDefaults.standardUserDefaults synchronize];
self.areaCodeTextField.text = countryCode;
NSInteger length = [[FUSCountryHelper sharedInstance] lengthForPhoneNumberWithCountryCode:countryCode];
if (length == 0) length = 13;
self.phoneTextField.textMaxLength = length;
}else {
self.countryInfoDict = nil;
self.countryLabel.text = [NSString fus_versionLocalString:@"未知国家"];
self.countryLabel.textAlignment = NSTextAlignmentRight;
}
self.countryLabel.text = countryName;
self.countryLabel.textAlignment = NSTextAlignmentRight;
[[NSUserDefaults standardUserDefaults] setObject:self.countryInfoDict forKey:USER_COUNTRY_INFO];
self.areaCodeLabel.text = [NSString stringWithFormat:@"+%@", countryCode];
NSInteger length = [[FUSCountryHelper sharedInstance] lengthForPhoneNumberWithCountryCode:countryCode];
if (length == 0) length = 13;
self.phoneTextField.textMaxLength = length;
if (![NSString isNull:self.phone]) {
self.phoneTextField.text = self.phone;
}
// if (!self.countryInfoDict) {
//
// self.countryInfoDict = [[FUSCountryHelper sharedInstance] fus_getCountryInfoForCountryName:@"Taiwan"];
// }
//
// NSString *countryName = [_countryInfoDict objectForKey:FUSCountryLocaleNameKey];
// NSString *countryCode = [_countryInfoDict objectForKey:FUSCountryCodeKey];
//
// if ([NSString isNull:countryName]) {
// self.countryInfoDict = [[FUSCountryHelper sharedInstance] fus_getCountryInfoForCountryCode:countryCode];
// [self displayCountryNameAndCountryCode];
// return;
// }
//
// self.countryLabel.text = countryName;
// self.countryLabel.textAlignment = NSTextAlignmentRight;
// [[NSUserDefaults standardUserDefaults] setObject:self.countryInfoDict forKey:USER_COUNTRY_INFO];
//
// NSInteger length = [[FUSCountryHelper sharedInstance] lengthForPhoneNumberWithCountryCode:countryCode];
// if (length == 0) length = 13;
// self.phoneTextField.textMaxLength = length;
//
// if (![NSString isNull:self.phone]) {
// self.phoneTextField.text = self.phone;
// }
}
/**
......
......@@ -68,4 +68,11 @@ typedef void(^countryCompletion)(NSString *country);
*/
- (NSInteger)lengthForPhoneNumberWithCountryCode:(NSString *)countryCode;
/// 根据区码获取国家编号列表,几个获取几个
/// @param countryCode 区码
- (NSArray *)fus_getCountryInfoListForCountryCode:(NSString *)countryCode;
/// 获取被ban的国家
-(NSArray *)getBanCountryNamesArr;
@end
......@@ -170,6 +170,48 @@ NSString * const FUSCountryCodeKey = @"country_code";
return examplePhone.nationalNumber.description.length;
}
- (NSArray *)fus_getCountryInfoListForCountryCode:(NSString *)countryCode{
if (!countryCode || countryCode.length <= 0) {
return nil;
}
// 将符合条件的国家筛选出来
NSMutableArray *resCountriesArr = [[NSMutableArray alloc] init];
NSDictionary *countriesDict = [self fus_getAllCountries];
NSArray *allKeys = [countriesDict.allKeys sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
return [obj1 compare:obj2 options:NSLiteralSearch];
}];
[allKeys enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
for (NSDictionary *countryDict in countriesDict[obj]) {
NSString *countryCodeStr = countryDict[FUSCountryCodeKey];
if (countryCodeStr.length <= 0) {
continue;
}
if ([countryCodeStr rangeOfString:countryCode].location == 0) {
[resCountriesArr addObject:countryDict];
}
}
}];
// 讲特殊要求优先级最高的国家排到第一位
NSString *preferentialCountryName = [self fus_getPreferentialCountry][countryCode];
if (preferentialCountryName != nil && preferentialCountryName.length > 0) {
__block NSDictionary *tempDict = nil;
__block NSUInteger targetInt = 0;
[resCountriesArr enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj[@"en_ctr"] isEqualToString:preferentialCountryName]){
tempDict = obj;
targetInt = idx;
*stop = YES;
}
}];
if (tempDict != nil && targetInt > 0) {
[resCountriesArr removeObjectAtIndex:targetInt];
[resCountriesArr insertObject:tempDict atIndex:0];
}
}
return resCountriesArr;
}
#pragma mark - Method
/**
......@@ -334,6 +376,33 @@ NSString * const FUSCountryCodeKey = @"country_code";
FUSLogInfo(@"");
}
/// 取到优先的国家地区
-(NSDictionary *)fus_getPreferentialCountry{
return @{@"44": @"United Kingdom"};
}
-(NSArray *)getBanCountryNamesArr{
return @[@"Afghanistan",
@"Belarus",
@"Congo",
@"Congo The Democratic Republic",
@"Cuba",
@"Haiti",
@"Iran",
@"Iraq",
@"North Korea",
@"Mali",
@"Mozambique",
@"Myanmar",
@"Russia",
@"Somalia",
@"South Sudan",
@"Sudan",
@"Syria",
@"Venezuela",
@"Yemen"];
}
- (NSDictionary *)getCountryDict
{
return @{@"AC":@"Ascension Island",
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,6 +3,7 @@ CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/FUSFoundation
FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking" "${PODS_CONFIGURATION_BUILD_DIR}/AppAuth" "${PODS_CONFIGURATION_BUILD_DIR}/CocoaAsyncSocket" "${PODS_CONFIGURATION_BUILD_DIR}/FMDB" "${PODS_CONFIGURATION_BUILD_DIR}/GTMAppAuth" "${PODS_CONFIGURATION_BUILD_DIR}/GTMSessionFetcher" "${PODS_CONFIGURATION_BUILD_DIR}/HWPanModal" "${PODS_CONFIGURATION_BUILD_DIR}/MBProgressHUD" "${PODS_CONFIGURATION_BUILD_DIR}/MJRefresh" "${PODS_CONFIGURATION_BUILD_DIR}/Masonry" "${PODS_CONFIGURATION_BUILD_DIR}/RMStore" "${PODS_CONFIGURATION_BUILD_DIR}/TalkingData" "${PODS_CONFIGURATION_BUILD_DIR}/UIImage+BlurredFrame" "${PODS_CONFIGURATION_BUILD_DIR}/YYKit" "${PODS_CONFIGURATION_BUILD_DIR}/ZipArchive" "${PODS_CONFIGURATION_BUILD_DIR}/libPhoneNumber-iOS" "${PODS_ROOT}/FacebookSDK" "${PODS_ROOT}/GoogleSignIn/Frameworks" "${PODS_ROOT}/LineSDK/LineSDK" "${PODS_ROOT}/MOBFoundation/MOBFoundation" "${PODS_ROOT}/TwitterCore/iOS" "${PODS_ROOT}/TwitterKit5/iOS" "${PODS_ROOT}/YYKit/Vendor" "${PODS_ROOT}/mob_sharesdk/ShareSDK" "${PODS_ROOT}/mob_sharesdk/ShareSDK/Support/PlatformConnector" "${PODS_ROOT}/mob_sharesdk/ShareSDK/Support/Required" "${PODS_XCFRAMEWORKS_BUILD_DIR}/MOBFoundation"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public"
OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS -suppress-warnings
PODS_BUILD_DIR = ${BUILD_DIR}
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_DEVELOPMENT_LANGUAGE = ${DEVELOPMENT_LANGUAGE}
......
......@@ -3,6 +3,7 @@ CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/FUSFoundation
FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking" "${PODS_CONFIGURATION_BUILD_DIR}/AppAuth" "${PODS_CONFIGURATION_BUILD_DIR}/CocoaAsyncSocket" "${PODS_CONFIGURATION_BUILD_DIR}/FMDB" "${PODS_CONFIGURATION_BUILD_DIR}/GTMAppAuth" "${PODS_CONFIGURATION_BUILD_DIR}/GTMSessionFetcher" "${PODS_CONFIGURATION_BUILD_DIR}/HWPanModal" "${PODS_CONFIGURATION_BUILD_DIR}/MBProgressHUD" "${PODS_CONFIGURATION_BUILD_DIR}/MJRefresh" "${PODS_CONFIGURATION_BUILD_DIR}/Masonry" "${PODS_CONFIGURATION_BUILD_DIR}/RMStore" "${PODS_CONFIGURATION_BUILD_DIR}/TalkingData" "${PODS_CONFIGURATION_BUILD_DIR}/UIImage+BlurredFrame" "${PODS_CONFIGURATION_BUILD_DIR}/YYKit" "${PODS_CONFIGURATION_BUILD_DIR}/ZipArchive" "${PODS_CONFIGURATION_BUILD_DIR}/libPhoneNumber-iOS" "${PODS_ROOT}/FacebookSDK" "${PODS_ROOT}/GoogleSignIn/Frameworks" "${PODS_ROOT}/LineSDK/LineSDK" "${PODS_ROOT}/MOBFoundation/MOBFoundation" "${PODS_ROOT}/TwitterCore/iOS" "${PODS_ROOT}/TwitterKit5/iOS" "${PODS_ROOT}/YYKit/Vendor" "${PODS_ROOT}/mob_sharesdk/ShareSDK" "${PODS_ROOT}/mob_sharesdk/ShareSDK/Support/PlatformConnector" "${PODS_ROOT}/mob_sharesdk/ShareSDK/Support/Required" "${PODS_XCFRAMEWORKS_BUILD_DIR}/MOBFoundation"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public"
OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS -suppress-warnings
PODS_BUILD_DIR = ${BUILD_DIR}
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_DEVELOPMENT_LANGUAGE = ${DEVELOPMENT_LANGUAGE}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment