Commit 6fabb5dc86ad555c4bfeb882041543e0fdd81712
1 parent
62efcb21
no message
Showing
20 changed files
with
1811 additions
and
306 deletions
CNLiveLoginModule/Classes/View/CNLiveLoginHeaderView.h renamed to CNLiveLoginModule/Classes/Controller/CNLiveCompleteInfoController.h
| 1 | 1 | // |
| 2 | -// CNLiveLoginHeaderView.h | |
| 3 | -// CNLiveMineModule | |
| 2 | +// CNLiveCompleteInfoController.h | |
| 3 | +// CNLiveLoginModule | |
| 4 | 4 | // |
| 5 | 5 | // Created by 153993236@qq.com on 11/12/2019. |
| 6 | -// Copyright © 2019 153993236@qq.com. All rights reserved. | |
| 6 | +// Copyright (c) 2019 153993236@qq.com. All rights reserved. | |
| 7 | 7 | // |
| 8 | 8 | |
| 9 | 9 | #import <UIKit/UIKit.h> |
| 10 | 10 | |
| 11 | 11 | NS_ASSUME_NONNULL_BEGIN |
| 12 | 12 | |
| 13 | -@interface CNLiveLoginHeaderView : UIView | |
| 14 | -- (void)layoutSubviews; | |
| 13 | +@interface CNLiveCompleteInfoController : UIViewController | |
| 14 | +@property (nonatomic, assign) BOOL isShow; | |
| 15 | 15 | |
| 16 | 16 | @end |
| 17 | 17 | ... | ... |
CNLiveLoginModule/Classes/Controller/CNLiveCompleteInfoController.m
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveCompleteInfoController.m | |
| 3 | +// CNLiveLoginModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright (c) 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "CNLiveCompleteInfoController.h" | |
| 10 | + | |
| 11 | +#import "MJExtension.h" | |
| 12 | +#import "QMUIKit.h" | |
| 13 | +#import "YYKit.h" | |
| 14 | + | |
| 15 | +#import "CNLiveThreeLoginType.h" | |
| 16 | +#import "CNLiveBindingTelView.h" | |
| 17 | + | |
| 18 | +#define HexColor(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] | |
| 19 | + | |
| 20 | +@interface CNLiveCompleteInfoController()<CNLiveBindingTelViewDelegate> | |
| 21 | +@property (nonatomic, assign) CNLiveThreeLoginType type; | |
| 22 | +@property (nonatomic, weak) CNLiveBindingTelView *bindingTelView; | |
| 23 | +@property (nonatomic, weak) YYLabel *protocol; | |
| 24 | + | |
| 25 | +@end | |
| 26 | + | |
| 27 | +@implementation CNLiveCompleteInfoController | |
| 28 | +- (instancetype)initWithType:(CNLiveThreeLoginType)type{ | |
| 29 | + self = [super init]; | |
| 30 | + if (self) { | |
| 31 | + self.type = type; | |
| 32 | + | |
| 33 | + } | |
| 34 | + return self; | |
| 35 | + | |
| 36 | +} | |
| 37 | + | |
| 38 | +- (void)viewDidLoad { | |
| 39 | + [super viewDidLoad]; | |
| 40 | + // Do any additional setup after loading the view. | |
| 41 | + self.automaticallyAdjustsScrollViewInsets = NO; | |
| 42 | + self.navigationController.navigationBar.translucent = NO; | |
| 43 | + self.extendedLayoutIncludesOpaqueBars = YES; | |
| 44 | + self.edgesForExtendedLayout = UIRectEdgeBottom; | |
| 45 | + self.view.backgroundColor = [UIColor whiteColor]; | |
| 46 | + self.title = @"绑定手机号"; | |
| 47 | + | |
| 48 | + CNLiveBindingTelView *bindingTelView = [[CNLiveBindingTelView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/8.0, NavigationContentTop, self.view.frame.size.width*3/4.0, 400) type:self.type]; | |
| 49 | + bindingTelView.delegate = self; | |
| 50 | + [self.view addSubview:bindingTelView]; | |
| 51 | + self.bindingTelView = bindingTelView; | |
| 52 | + | |
| 53 | + YYLabel *protocol = [[YYLabel alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-30-NavigationContentTop-SafeAreaInsetsConstantForDeviceWithNotch.bottom, self.view.frame.size.width, 30)]; | |
| 54 | + protocol.textAlignment = NSTextAlignmentCenter; | |
| 55 | + protocol.textColor = HexColor(0xadadad); | |
| 56 | + protocol.font = [UIFont systemFontOfSize:14.0]; | |
| 57 | + NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"已阅读并同意《账户绑定确认书(网家家)》"]; | |
| 58 | + NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; | |
| 59 | + style.alignment = NSTextAlignmentCenter;//对齐方式 | |
| 60 | + [text addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, text.length)]; | |
| 61 | + text.color = HexColor(0xadadad); | |
| 62 | + text.font = [UIFont systemFontOfSize:14.0]; | |
| 63 | + __weak typeof(self) weakSelf = self; | |
| 64 | + [text setTextHighlightRange:NSMakeRange(7, 12) color:[UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { | |
| 65 | + __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 66 | + if(!strongSelf) return; | |
| 67 | + [strongSelf.view endEditing:YES]; | |
| 68 | +// [XWAgreementManager jumpToAgreementH5WithType:XWAgreementTypeBindingLogin]; | |
| 69 | + | |
| 70 | + }]; | |
| 71 | + protocol.attributedText = text; | |
| 72 | + [self.view addSubview:protocol]; | |
| 73 | + self.protocol = protocol; | |
| 74 | + | |
| 75 | +} | |
| 76 | + | |
| 77 | +- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { | |
| 78 | + [self.view endEditing:YES]; | |
| 79 | + | |
| 80 | +} | |
| 81 | + | |
| 82 | +#pragma mark - CNLiveBindingTelViewDelegate | |
| 83 | +- (void)bindingSuccess:(CNLiveBindingTelView *)view type:(CNLiveThreeLoginType)type{ | |
| 84 | + | |
| 85 | +} | |
| 86 | + | |
| 87 | +/* | |
| 88 | +#pragma mark - Navigation | |
| 89 | + | |
| 90 | +// In a storyboard-based application, you will often want to do a little preparation before navigation | |
| 91 | +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | |
| 92 | + // Get the new view controller using [segue destinationViewController]. | |
| 93 | + // Pass the selected object to the new view controller. | |
| 94 | +} | |
| 95 | +*/ | |
| 96 | + | |
| 97 | +#pragma mark - 懒加载 | |
| 98 | + | |
| 99 | +/** | |
| 100 | + * 创建图片 | |
| 101 | + * | |
| 102 | + * @param imageName 图片名字 | |
| 103 | + * @param bundleName 图片所在的bundle名字 | |
| 104 | + * @param targetClass 类和bundle的同级目录 | |
| 105 | + * @return 返回UIImage | |
| 106 | + */ | |
| 107 | +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{ | |
| 108 | + NSBundle *bundle = [NSBundle bundleForClass:targetClass]; | |
| 109 | + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"]; | |
| 110 | + NSBundle *targetBundle = [NSBundle bundleWithURL:url]; | |
| 111 | + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil]; | |
| 112 | + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil]; | |
| 113 | +} | |
| 114 | + | |
| 115 | +@end | ... | ... |
CNLiveLoginModule/Classes/ThreeLogin/CNLiveBindingTelController.h
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveBindingTelController.h | |
| 3 | +// CNLiveLoginModule | |
| 4 | +// | |
| 5 | +// Created by CNLive-zxw on 2019/9/9. | |
| 6 | +// Copyright © 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <UIKit/UIKit.h> | |
| 10 | +#import "CNLiveThreeLoginType.h" | |
| 11 | + | |
| 12 | +NS_ASSUME_NONNULL_BEGIN | |
| 13 | + | |
| 14 | +@interface CNLiveBindingTelController : UIViewController | |
| 15 | +- (instancetype)initWithType:(CNLiveThreeLoginType)type; | |
| 16 | + | |
| 17 | + | |
| 18 | +@end | |
| 19 | + | |
| 20 | +NS_ASSUME_NONNULL_END | ... | ... |
CNLiveLoginModule/Classes/ThreeLogin/CNLiveBindingTelController.m
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveBindingTelController.m | |
| 3 | +// CNLiveLoginModule | |
| 4 | +// | |
| 5 | +// Created by CNLive-zxw on 2019/9/9. | |
| 6 | +// Copyright © 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "CNLiveBindingTelController.h" | |
| 10 | + | |
| 11 | +#import "YYKit.h" | |
| 12 | +#import "NSAttributedString+YYText.h" | |
| 13 | +#import "QMUIKit.h" | |
| 14 | + | |
| 15 | +#import "CNLiveBindingTelView.h" | |
| 16 | + | |
| 17 | +@interface CNLiveBindingTelController()<CNLiveBindingTelViewDelegate> | |
| 18 | +@property (nonatomic, assign) CNLiveThreeLoginType type; | |
| 19 | +@property (nonatomic, weak) CNLiveBindingTelView *bindingTelView; | |
| 20 | +@property (nonatomic, weak) YYLabel *protocol; | |
| 21 | + | |
| 22 | +@end | |
| 23 | + | |
| 24 | +@implementation CNLiveBindingTelController | |
| 25 | +- (instancetype)initWithType:(CNLiveThreeLoginType)type{ | |
| 26 | + self = [super init]; | |
| 27 | + if (self) { | |
| 28 | + self.type = type; | |
| 29 | + | |
| 30 | + } | |
| 31 | + return self; | |
| 32 | + | |
| 33 | +} | |
| 34 | + | |
| 35 | +- (void)viewDidLoad { | |
| 36 | + [super viewDidLoad]; | |
| 37 | + // Do any additional setup after loading the view. | |
| 38 | + self.automaticallyAdjustsScrollViewInsets = NO; | |
| 39 | + self.navigationController.navigationBar.translucent = NO; | |
| 40 | + self.extendedLayoutIncludesOpaqueBars = YES; | |
| 41 | + self.edgesForExtendedLayout = UIRectEdgeBottom; | |
| 42 | + self.view.backgroundColor = [UIColor whiteColor]; | |
| 43 | + self.title = @"绑定手机号"; | |
| 44 | + | |
| 45 | + CNLiveBindingTelView *bindingTelView = [[CNLiveBindingTelView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/8.0, NavigationContentTop, self.view.frame.size.width*3/4.0, 400) type:self.type]; | |
| 46 | + bindingTelView.delegate = self; | |
| 47 | + [self.view addSubview:bindingTelView]; | |
| 48 | + self.bindingTelView = bindingTelView; | |
| 49 | + | |
| 50 | + YYLabel *protocol = [[YYLabel alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-30-NavigationContentTop-SafeAreaInsetsConstantForDeviceWithNotch.bottom, self.view.frame.size.width, 30)]; | |
| 51 | + protocol.textAlignment = NSTextAlignmentCenter; | |
| 52 | + protocol.textColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0]; | |
| 53 | + protocol.font = [UIFont systemFontOfSize:14.0]; | |
| 54 | + NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"已阅读并同意《账户绑定确认书(网家家)》"]; | |
| 55 | + NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; | |
| 56 | + style.alignment = NSTextAlignmentCenter;//对齐方式 | |
| 57 | + [text addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, text.length)]; | |
| 58 | + text.color = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0]; | |
| 59 | + text.font = [UIFont systemFontOfSize:14.0]; | |
| 60 | + __weak typeof(self) weakSelf = self; | |
| 61 | + [text setTextHighlightRange:NSMakeRange(7, 12) color:[UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { | |
| 62 | + __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 63 | + if(!strongSelf) return; | |
| 64 | + [strongSelf.view endEditing:YES]; | |
| 65 | +// [XWAgreementManager jumpToAgreementH5WithType:XWAgreementTypeBindingLogin]; | |
| 66 | + | |
| 67 | + }]; | |
| 68 | + protocol.attributedText = text; | |
| 69 | + [self.view addSubview:protocol]; | |
| 70 | + self.protocol = protocol; | |
| 71 | + | |
| 72 | +} | |
| 73 | + | |
| 74 | +- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { | |
| 75 | + [self.view endEditing:YES]; | |
| 76 | + | |
| 77 | +} | |
| 78 | + | |
| 79 | +#pragma mark - CNLiveBindingTelViewDelegate | |
| 80 | +- (void)bindingSuccess:(CNLiveBindingTelView *)view type:(CNLiveThreeLoginType)type{ | |
| 81 | + | |
| 82 | +} | |
| 83 | + | |
| 84 | +/* | |
| 85 | +#pragma mark - Navigation | |
| 86 | + | |
| 87 | +// In a storyboard-based application, you will often want to do a little preparation before navigation | |
| 88 | +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | |
| 89 | + // Get the new view controller using [segue destinationViewController]. | |
| 90 | + // Pass the selected object to the new view controller. | |
| 91 | +} | |
| 92 | +*/ | |
| 93 | + | |
| 94 | +@end | ... | ... |
CNLiveLoginModule/Classes/ThreeLogin/CNLiveBindingTelView.h
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveBindingTelView.h | |
| 3 | +// XWLoginModule_Example | |
| 4 | +// | |
| 5 | +// Created by CNLive-zxw on 2019/9/6. | |
| 6 | +// Copyright © 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <UIKit/UIKit.h> | |
| 10 | +#import "CNLiveThreeLoginType.h" | |
| 11 | + | |
| 12 | +NS_ASSUME_NONNULL_BEGIN | |
| 13 | + | |
| 14 | +@class CNLiveBindingTelView; | |
| 15 | +@protocol CNLiveBindingTelViewDelegate <NSObject> | |
| 16 | +- (void)bindingSuccess:(CNLiveBindingTelView *)view type:(CNLiveThreeLoginType)type; | |
| 17 | + | |
| 18 | +@end | |
| 19 | + | |
| 20 | +@interface CNLiveBindingTelView : UIView | |
| 21 | +@property (nonatomic, weak) id<CNLiveBindingTelViewDelegate> delegate; | |
| 22 | +- (instancetype)initWithFrame:(CGRect)frame type:(CNLiveThreeLoginType)type; | |
| 23 | + | |
| 24 | +@end | |
| 25 | + | |
| 26 | +NS_ASSUME_NONNULL_END | ... | ... |
CNLiveLoginModule/Classes/ThreeLogin/CNLiveBindingTelView.m
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveBindingTelView.m | |
| 3 | +// XWLoginModule_Example | |
| 4 | +// | |
| 5 | +// Created by CNLive-zxw on 2019/9/6. | |
| 6 | +// Copyright © 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "CNLiveBindingTelView.h" | |
| 10 | +#import "YYKit.h" | |
| 11 | +#import "CNLiveLoginCountryView.h" | |
| 12 | + | |
| 13 | +#import "CNLiveLoginCountryView.h" | |
| 14 | +#import "CNLiveLoginTextField.h" | |
| 15 | +#import "CNLiveCountdownButton.h" | |
| 16 | + | |
| 17 | +@interface CNLiveBindingTelView()<UITextFieldDelegate,CNLiveCountDownButtonDataSource, CNLiveCountDownButtonDelegate> | |
| 18 | +{ | |
| 19 | + NSString *_countryCode; // 国家Code | |
| 20 | + NSString *_verificationCode; // 验证码 | |
| 21 | +} | |
| 22 | + | |
| 23 | +@property (nonatomic, weak) CNLiveLoginTextField *account; | |
| 24 | +@property (nonatomic, weak) CNLiveLoginTextField *code; | |
| 25 | +@property (nonatomic, strong) CNLiveCountDownButton *countDown; | |
| 26 | +@property (nonatomic, weak) UIButton *binding; | |
| 27 | +@property (nonatomic, assign) CNLiveThreeLoginType type; | |
| 28 | + | |
| 29 | +@end | |
| 30 | + | |
| 31 | +@implementation CNLiveBindingTelView | |
| 32 | +static NSInteger const rowHeight = 40; | |
| 33 | +static NSInteger const space = 40; | |
| 34 | + | |
| 35 | +- (instancetype)initWithFrame:(CGRect)frame type:(CNLiveThreeLoginType)type{ | |
| 36 | + | |
| 37 | + self = [super initWithFrame:frame]; | |
| 38 | + if (self) { | |
| 39 | + self.userInteractionEnabled = YES; | |
| 40 | + _countryCode = @"86"; | |
| 41 | + self.type = type; | |
| 42 | + [self createSubviews:frame]; | |
| 43 | + | |
| 44 | + } | |
| 45 | + return self; | |
| 46 | + | |
| 47 | +} | |
| 48 | +- (void)createSubviews:(CGRect)frame{ | |
| 49 | + | |
| 50 | + CNLiveLoginTextField *account = [[CNLiveLoginTextField alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, rowHeight)]; | |
| 51 | + account.keyboardType = UIKeyboardTypeNumberPad; | |
| 52 | + account.placeholder = @"请输入手机号"; | |
| 53 | + account.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]; | |
| 54 | + account.placeholderColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0]; | |
| 55 | + account.font = [UIFont systemFontOfSize:16]; | |
| 56 | + account.textAlignment = NSTextAlignmentLeft; | |
| 57 | + [account addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; | |
| 58 | + account.clearButtonMode = UITextFieldViewModeWhileEditing; | |
| 59 | + account.delegate = self; | |
| 60 | + [self addSubview:account]; | |
| 61 | + self.account = account; | |
| 62 | + | |
| 63 | + CNLiveLoginTextField *code = [[CNLiveLoginTextField alloc] initWithFrame:CGRectMake(account.left, account.bottom+space, frame.size.width/2.0, rowHeight)]; | |
| 64 | + code.keyboardType = UIKeyboardTypeNumberPad; | |
| 65 | + code.placeholder = @"请输入验证码"; | |
| 66 | + code.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]; | |
| 67 | + code.placeholderColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0]; | |
| 68 | + code.font = [UIFont systemFontOfSize:16]; | |
| 69 | + code.textAlignment = NSTextAlignmentLeft; | |
| 70 | + [code addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; | |
| 71 | + code.clearButtonMode = UITextFieldViewModeWhileEditing; | |
| 72 | + code.delegate = self; | |
| 73 | + [self addSubview:code]; | |
| 74 | + self.code = code; | |
| 75 | + | |
| 76 | + CNLiveCountDownButton *countDown = [CNLiveCountDownButton buttonWithType:UIButtonTypeCustom]; | |
| 77 | + countDown.dataSource = self; | |
| 78 | + countDown.delegate = self; | |
| 79 | + countDown.frame = CGRectMake(frame.size.width-80, account.bottom+space+10, 80, rowHeight-10); | |
| 80 | + UIImage *image2 = [self xw_getImageName:@"login_get_code" bundleName:@"CNLiveLoginModule" targetClass:[self class]]; | |
| 81 | + [countDown setImage:image2 forState:UIControlStateNormal]; | |
| 82 | + countDown.adjustsImageWhenHighlighted = NO; | |
| 83 | + [countDown setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; | |
| 84 | + countDown.titleLabel.font = [UIFont systemFontOfSize:12.0]; | |
| 85 | + countDown.layer.cornerRadius = 15; | |
| 86 | + countDown.layer.masksToBounds = YES; | |
| 87 | + [self addSubview:countDown]; | |
| 88 | + self.countDown = countDown; | |
| 89 | + | |
| 90 | + UIButton *binding = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 91 | + binding.frame = CGRectMake(5, code.bottom+space, frame.size.width-10, rowHeight); | |
| 92 | + [binding setTitle:@"确认手机绑定并同意协议" forState:UIControlStateNormal]; | |
| 93 | + [binding setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; | |
| 94 | + binding.titleLabel.font = [UIFont systemFontOfSize:15.0]; | |
| 95 | + binding.backgroundColor = [UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0]; | |
| 96 | + binding.layer.cornerRadius = 20; | |
| 97 | + binding.layer.masksToBounds = YES; | |
| 98 | + binding.adjustsImageWhenHighlighted = NO; | |
| 99 | + [binding addTarget:self action:@selector(bindingDidClicked:) forControlEvents:UIControlEventTouchUpInside]; | |
| 100 | + [self addSubview:binding]; | |
| 101 | + self.binding = binding; | |
| 102 | + | |
| 103 | +} | |
| 104 | + | |
| 105 | +#pragma mark - UITextFieldDelegate | |
| 106 | +- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ | |
| 107 | + if ([textField isEqual:_account] || [textField isEqual:_code]) { | |
| 108 | + return YES; | |
| 109 | + | |
| 110 | + } | |
| 111 | + else { | |
| 112 | + return YES; | |
| 113 | + | |
| 114 | + } | |
| 115 | +} | |
| 116 | + | |
| 117 | +- (void)textFieldDidChange:(UITextField *)textField { | |
| 118 | + if (![_account.text isEqualToString:@""] && ![_code.text isEqualToString:@""]) { | |
| 119 | + _binding.enabled = YES; | |
| 120 | + | |
| 121 | + } | |
| 122 | + else { | |
| 123 | + _binding.enabled = NO; | |
| 124 | + | |
| 125 | + } | |
| 126 | + | |
| 127 | +} | |
| 128 | + | |
| 129 | +- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { | |
| 130 | + if ([textField isEqual:_account]) { | |
| 131 | + NSInteger maxTextLength = 20; | |
| 132 | + if(string.length == 0) { | |
| 133 | + //判断是不是删除键 | |
| 134 | + return YES; | |
| 135 | + } | |
| 136 | + else if(textField.text.length >= maxTextLength) { | |
| 137 | + NSLog(@"输入的字符个数大于20,忽略输入"); | |
| 138 | + return NO; | |
| 139 | + } | |
| 140 | + else if (![self isNum:string]) { | |
| 141 | + return NO; | |
| 142 | + } | |
| 143 | + else if (textField.text.length + string.length > maxTextLength){ | |
| 144 | + NSInteger length = textField.text.length; | |
| 145 | + NSInteger needLen = maxTextLength - length; | |
| 146 | + textField.text = [textField.text stringByAppendingString:[string substringToIndex:needLen]]; | |
| 147 | + return NO; | |
| 148 | + } | |
| 149 | + else{ | |
| 150 | + return YES; | |
| 151 | + } | |
| 152 | + } | |
| 153 | + else if ([textField isEqual:self.code]){ | |
| 154 | + NSInteger maxTextLength = 6; | |
| 155 | + if(string.length == 0) { | |
| 156 | + //判断是不是删除键 | |
| 157 | + return YES; | |
| 158 | + } | |
| 159 | + else if(textField.text.length >= maxTextLength) { | |
| 160 | + NSLog(@"输入的字符个数大于6,忽略输入"); | |
| 161 | + return NO; | |
| 162 | + } | |
| 163 | + else if (![self isNum:string]) { | |
| 164 | + return NO; | |
| 165 | + } | |
| 166 | + else if (textField.text.length + string.length > maxTextLength){ | |
| 167 | + NSInteger length = textField.text.length; | |
| 168 | + NSInteger needLen = maxTextLength - length; | |
| 169 | + textField.text = [textField.text stringByAppendingString:[string substringToIndex:needLen]]; | |
| 170 | + return NO; | |
| 171 | + } | |
| 172 | + else{ | |
| 173 | + return YES; | |
| 174 | + } | |
| 175 | + } | |
| 176 | + else{ | |
| 177 | + return YES; | |
| 178 | + } | |
| 179 | +} | |
| 180 | + | |
| 181 | +/** 判断是否为纯数字 */ | |
| 182 | +- (BOOL)isNum:(NSString *)checkedNumString { | |
| 183 | + checkedNumString = [checkedNumString stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]]; | |
| 184 | + if(checkedNumString.length > 0) { | |
| 185 | + return NO; | |
| 186 | + } | |
| 187 | + return YES; | |
| 188 | +} | |
| 189 | + | |
| 190 | +/* | |
| 191 | + // Only override drawRect: if you perform custom drawing. | |
| 192 | + // An empty implementation adversely affects performance during animation. | |
| 193 | + - (void)drawRect:(CGRect)rect { | |
| 194 | + // Drawing code | |
| 195 | + } | |
| 196 | + */ | |
| 197 | + | |
| 198 | +#pragma mark - CNLiveCountdownButton DataSource | |
| 199 | +// 设置倒计时总秒数 | |
| 200 | +- (NSInteger)startCountDownNumOfCountDownButton:(CNLiveCountDownButton *)countdownButton { | |
| 201 | + return 60; | |
| 202 | +} | |
| 203 | + | |
| 204 | +#pragma mark - CNLiveCountdownButton Delegate | |
| 205 | +// 倒计时按钮点击 | |
| 206 | +- (void)countDownButtonDidClick:(CNLiveCountDownButton *)button { | |
| 207 | + //获取验证码 | |
| 208 | + if ([_account.text isEqualToString:@""]) { | |
| 209 | +// [XWAlertView alertViewWithFlexTextMessage:@"请输入手机号" view:self.superview]; | |
| 210 | + return; | |
| 211 | + } | |
| 212 | + // 按钮点击后将enabled设置为NO | |
| 213 | + button.userInteractionEnabled = NO; | |
| 214 | + __weak typeof(self) weakSelf = self; | |
| 215 | +// [XWUserRequest verificationCodeWithType:XWCodeTypeShortcutLogin mobile:_account.text countryCode:_countryCode success:^(id _Nonnull result) { | |
| 216 | +// __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 217 | +// if(!strongSelf) return; | |
| 218 | +// // 获取的验证码 | |
| 219 | +// strongSelf->_verificationCode = @"666666"; | |
| 220 | +// | |
| 221 | +// [XWAlertView alertSucceedViewWithTextMessage:@"获取成功" view:strongSelf.superview]; | |
| 222 | +// button.backgroundColor = HexColor(0xdedede); | |
| 223 | +// button.frame = CGRectMake(self.frame.size.width-110, self.account.bottom+space+10, 110, rowHeight-10); | |
| 224 | +// [button setImage:nil forState:UIControlStateNormal]; | |
| 225 | +// NSString *title = [NSString stringWithFormat:@"%d秒后重新发送", 60]; | |
| 226 | +// [button setTitle:title forState:UIControlStateNormal]; | |
| 227 | +// [button startCountDown]; | |
| 228 | +// | |
| 229 | +// } failure:^(NSDictionary * _Nonnull errorDic) { | |
| 230 | +// __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 231 | +// if(!strongSelf) return; | |
| 232 | +// button.userInteractionEnabled = YES; | |
| 233 | +// [XWAlertView alertErrorViewWithTextMessage:@"获取失败" view:strongSelf.superview]; | |
| 234 | +// | |
| 235 | +// }]; | |
| 236 | + | |
| 237 | +} | |
| 238 | + | |
| 239 | +// 倒计时进行中 | |
| 240 | +- (void)countDownButtonDidCountDown:(CNLiveCountDownButton *)button countDownNum:(NSInteger)countDownNum { | |
| 241 | + if(button.frame.size.width != 110){ | |
| 242 | + button.frame = CGRectMake(self.frame.size.width-110, self.account.bottom+space+10, 110, rowHeight-10); | |
| 243 | + } | |
| 244 | + NSString *title = [NSString stringWithFormat:@"%ld秒后重新发送", countDownNum]; | |
| 245 | + [button setTitle:title forState:UIControlStateNormal]; | |
| 246 | + | |
| 247 | +} | |
| 248 | + | |
| 249 | +// 倒计时结束 | |
| 250 | +- (void)countDownButtonDidEndCountDown:(CNLiveCountDownButton *)button { | |
| 251 | + button.frame = CGRectMake(self.frame.size.width-80, self.account.bottom+space+10, 80, rowHeight-10); | |
| 252 | + button.backgroundColor = [UIColor whiteColor]; | |
| 253 | + button.userInteractionEnabled = YES; | |
| 254 | + [button setTitle:@"" forState:UIControlStateNormal]; | |
| 255 | + UIImage *image2 = [self xw_getImageName:@"login_get_code" bundleName:@"CNLiveLoginModule" targetClass:[self class]]; | |
| 256 | + [button setImage:image2 forState:UIControlStateNormal]; | |
| 257 | +} | |
| 258 | + | |
| 259 | +#pragma mark - Action | |
| 260 | +- (void)codeDidClicked:(UIButton *)btn{ | |
| 261 | + //获取验证码 | |
| 262 | + if ([_account.text isEqualToString:@""]) { | |
| 263 | +// [XWAlertView alertViewWithFlexTextMessage:@"请输入手机号" view:self.superview]; | |
| 264 | + return; | |
| 265 | + } | |
| 266 | + __weak typeof(self) weakSelf = self; | |
| 267 | +// [XWUserRequest verificationCodeWithType:XWCodeTypeShortcutLogin mobile:_account.text countryCode:_countryCode success:^(id _Nonnull result) { | |
| 268 | +// __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 269 | +// if(!strongSelf) return; | |
| 270 | +// [XWAlertView alertSucceedViewWithTextMessage:@"获取成功" view:strongSelf.superview]; | |
| 271 | +// strongSelf->_verificationCode = @"666666"; | |
| 272 | +// | |
| 273 | +// } failure:^(NSDictionary * _Nonnull errorDic) { | |
| 274 | +// __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 275 | +// if(!strongSelf) return; | |
| 276 | +// [XWAlertView alertErrorViewWithTextMessage:@"获取失败" view:strongSelf.superview]; | |
| 277 | +// | |
| 278 | +// }]; | |
| 279 | + | |
| 280 | +} | |
| 281 | + | |
| 282 | +- (void)bindingDidClicked:(UIButton *)btn{ | |
| 283 | + if (self.delegate && [self.delegate respondsToSelector:@selector(bindingSuccess:type:)]) { | |
| 284 | + [self.delegate bindingSuccess:self type:self.type]; | |
| 285 | + } | |
| 286 | +// [XWUserRequest thirdPartyLoginBindingWithUserName:_account.text verificationCode:_code.text countryCode:_countryCode model:User_Model fromId:nil success:^(id _Nonnull result) { | |
| 287 | +// | |
| 288 | +// } failure:^(NSDictionary * _Nonnull errorDic) { | |
| 289 | +// | |
| 290 | +// }]; | |
| 291 | + | |
| 292 | +} | |
| 293 | + | |
| 294 | +/** | |
| 295 | + * 创建图片 | |
| 296 | + * | |
| 297 | + * @param imageName 图片名字 | |
| 298 | + * @param bundleName 图片所在的bundle名字 | |
| 299 | + * @param targetClass 类和bundle的同级目录 | |
| 300 | + * @return 返回UIImage | |
| 301 | + */ | |
| 302 | +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{ | |
| 303 | + NSBundle *bundle = [NSBundle bundleForClass:targetClass]; | |
| 304 | + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"]; | |
| 305 | + NSBundle *targetBundle = [NSBundle bundleWithURL:url]; | |
| 306 | + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil]; | |
| 307 | + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil]; | |
| 308 | +} | |
| 309 | + | |
| 310 | +@end | ... | ... |
CNLiveLoginModule/Classes/ThreeLogin/CNLiveThreeLoginType.h
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveThreeLoginType.h | |
| 3 | +// XWLoginModule_Example | |
| 4 | +// | |
| 5 | +// Created by CNLive-zxw on 2019/9/9. | |
| 6 | +// Copyright © 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#ifndef CNLiveThreeLoginType_h | |
| 10 | +#define CNLiveThreeLoginType_h | |
| 11 | + | |
| 12 | +typedef NS_ENUM(NSInteger,CNLiveThreeLoginType) | |
| 13 | +{ | |
| 14 | + CNLiveThreeLoginType_UnKnown = -2, | |
| 15 | + //预定义的平台 | |
| 16 | + CNLiveThreeLoginType_Predefine_Begin = -1, | |
| 17 | + CNLiveThreeLoginType_Sina = 0, //新浪 | |
| 18 | + CNLiveThreeLoginType_WechatSession = 1, //微信聊天 | |
| 19 | + CNLiveThreeLoginType_WechatTimeLine = 2, //微信朋友圈 | |
| 20 | + CNLiveThreeLoginType_WechatFavorite = 3, //微信收藏 | |
| 21 | + CNLiveThreeLoginType_QQ = 4, //QQ聊天页面 | |
| 22 | + CNLiveThreeLoginType_Qzone = 5, //qq空间 | |
| 23 | +}; | |
| 24 | + | |
| 25 | +#endif /* CNLiveThreeLoginType_h */ | ... | ... |
CNLiveLoginModule/Classes/ThreeLogin/CNLiveThreeLoginView.h
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveThreeLoginView.h | |
| 3 | +// XWLoginModule_Example | |
| 4 | +// | |
| 5 | +// Created by CNLive-zxw on 2019/9/6. | |
| 6 | +// Copyright © 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <UIKit/UIKit.h> | |
| 10 | +#import "CNLiveThreeLoginType.h" | |
| 11 | + | |
| 12 | +NS_ASSUME_NONNULL_BEGIN | |
| 13 | + | |
| 14 | +@class CNLiveThreeLoginView; | |
| 15 | +@protocol CNLiveThreeLoginViewDelegate <NSObject> | |
| 16 | +- (void)clickedButton:(CNLiveThreeLoginView *)view type:(CNLiveThreeLoginType)type; | |
| 17 | + | |
| 18 | +@end | |
| 19 | +@interface CNLiveThreeLoginView : UIView | |
| 20 | +@property (nonatomic, weak) id<CNLiveThreeLoginViewDelegate> delegate; | |
| 21 | + | |
| 22 | +@end | |
| 23 | + | |
| 24 | +NS_ASSUME_NONNULL_END | ... | ... |
CNLiveLoginModule/Classes/ThreeLogin/CNLiveThreeLoginView.m
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveThreeLoginView.m | |
| 3 | +// XWLoginModule_Example | |
| 4 | +// | |
| 5 | +// Created by CNLive-zxw on 2019/9/6. | |
| 6 | +// Copyright © 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "CNLiveThreeLoginView.h" | |
| 10 | +#import "YYKit.h" | |
| 11 | + | |
| 12 | +//#import "WXApi.h" | |
| 13 | + | |
| 14 | +@interface CNLiveThreeLoginView() | |
| 15 | + | |
| 16 | +@end | |
| 17 | +@implementation CNLiveThreeLoginView | |
| 18 | +static NSInteger const rowHeight = 80; | |
| 19 | +- (instancetype)initWithFrame:(CGRect)frame{ | |
| 20 | + self = [super initWithFrame:frame]; | |
| 21 | + if (self) { | |
| 22 | + [self createSubviews:frame]; | |
| 23 | + | |
| 24 | + } | |
| 25 | + return self; | |
| 26 | + | |
| 27 | +} | |
| 28 | +- (void)createSubviews:(CGRect)frame{ | |
| 29 | + CGFloat width = frame.size.width; | |
| 30 | + CGFloat nameWidth = frame.size.width/3.0; | |
| 31 | + CGFloat lineLeft = 15; | |
| 32 | + CGFloat lineWidth = nameWidth - lineLeft*2; | |
| 33 | + | |
| 34 | + UILabel *leftLine = [[UILabel alloc] initWithFrame:CGRectMake(lineLeft, (rowHeight/4.0-1)/2.0, lineWidth, 1)]; | |
| 35 | + leftLine.backgroundColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0]; | |
| 36 | + [self addSubview:leftLine]; | |
| 37 | + | |
| 38 | + UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(lineLeft+lineWidth, 0, nameWidth+2*lineLeft, rowHeight/4.0)]; | |
| 39 | + name.textColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0]; | |
| 40 | + name.font = [UIFont systemFontOfSize:15]; | |
| 41 | + name.textAlignment = NSTextAlignmentCenter; | |
| 42 | + name.text = @"第三方账号登录"; | |
| 43 | + [self addSubview:name]; | |
| 44 | + | |
| 45 | + UILabel *rightLine = [[UILabel alloc] initWithFrame:CGRectMake(name.right, leftLine.top, leftLine.width, 1)]; | |
| 46 | + rightLine.backgroundColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0]; | |
| 47 | + [self addSubview:rightLine]; | |
| 48 | + | |
| 49 | + NSArray *pics = @[@"login_wechat",@"login_qq",@"login_weibo"]; | |
| 50 | + // 设置微信白名单 | |
| 51 | +// if(!([WXApi isWXAppInstalled]||[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"wechat://"]])){ | |
| 52 | +// pics = @[@"login_qq",@"login_weibo"]; | |
| 53 | +// } | |
| 54 | + CGFloat btnWidth = width/pics.count*1.0; | |
| 55 | + for(int i = 0; i < pics.count; i++){ | |
| 56 | + UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 57 | + btn.tag = 10000+i; | |
| 58 | + btn.frame = CGRectMake(btnWidth*i, name.bottom, btnWidth, rowHeight); | |
| 59 | + UIImage *image = [self xw_getImageName:pics[i] bundleName:@"CNLiveLoginModule" targetClass:[self class]]; | |
| 60 | + [btn setImage:image forState:UIControlStateNormal]; | |
| 61 | + btn.adjustsImageWhenHighlighted = NO; | |
| 62 | + [btn addTarget:self action:@selector(btnDidClicked:) forControlEvents:UIControlEventTouchUpInside]; | |
| 63 | + [self addSubview:btn]; | |
| 64 | + | |
| 65 | + } | |
| 66 | + | |
| 67 | +} | |
| 68 | +- (void)btnDidClicked:(UIButton *)btn{ | |
| 69 | +// if([WXApi isWXAppInstalled]||[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"wechat://"]]){ | |
| 70 | +// if (self.delegate && [self.delegate respondsToSelector:@selector(clickedButton:type:)]) { | |
| 71 | +// if (self.delegate && [self.delegate respondsToSelector:@selector(clickedButton:type:)]) { | |
| 72 | +// if(btn.tag == 10000){ | |
| 73 | +// [self.delegate clickedButton:self type:UMSocialPlatformType_WechatSession]; | |
| 74 | +// | |
| 75 | +// }else if (btn.tag == 10001){ | |
| 76 | +// [self.delegate clickedButton:self type:UMSocialPlatformType_QQ]; | |
| 77 | +// | |
| 78 | +// }else if(btn.tag == 10002){ | |
| 79 | +// [self.delegate clickedButton:self type:UMSocialPlatformType_Sina]; | |
| 80 | +// | |
| 81 | +// } | |
| 82 | +// } | |
| 83 | +// } | |
| 84 | +// }else{ | |
| 85 | +// if (self.delegate && [self.delegate respondsToSelector:@selector(clickedButton:type:)]) { | |
| 86 | +// if(btn.tag == 10000){ | |
| 87 | +// [self.delegate clickedButton:self type:UMSocialPlatformType_QQ]; | |
| 88 | +// | |
| 89 | +// }else if(btn.tag == 10001){ | |
| 90 | +// [self.delegate clickedButton:self type:UMSocialPlatformType_Sina]; | |
| 91 | +// | |
| 92 | +// } | |
| 93 | +// } | |
| 94 | +// } | |
| 95 | + | |
| 96 | +} | |
| 97 | + | |
| 98 | +/* | |
| 99 | +// Only override drawRect: if you perform custom drawing. | |
| 100 | +// An empty implementation adversely affects performance during animation. | |
| 101 | +- (void)drawRect:(CGRect)rect { | |
| 102 | + // Drawing code | |
| 103 | +} | |
| 104 | +*/ | |
| 105 | + | |
| 106 | +/** | |
| 107 | + * 创建图片 | |
| 108 | + * | |
| 109 | + * @param imageName 图片名字 | |
| 110 | + * @param bundleName 图片所在的bundle名字 | |
| 111 | + * @param targetClass 类和bundle的同级目录 | |
| 112 | + * @return 返回UIImage | |
| 113 | + */ | |
| 114 | +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{ | |
| 115 | + NSBundle *bundle = [NSBundle bundleForClass:targetClass]; | |
| 116 | + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"]; | |
| 117 | + NSBundle *targetBundle = [NSBundle bundleWithURL:url]; | |
| 118 | + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil]; | |
| 119 | + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil]; | |
| 120 | +} | |
| 121 | + | |
| 122 | +@end | ... | ... |
CNLiveLoginModule/Classes/View/CNLiveCompleteInfoView.h
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveCompleteInfoView.h | |
| 3 | +// CNLiveLoginModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright (c) 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <UIKit/UIKit.h> | |
| 10 | + | |
| 11 | +NS_ASSUME_NONNULL_BEGIN | |
| 12 | +@class CNLiveCompleteInfoView; | |
| 13 | +@protocol CNLiveUserInfoViewDelegate <NSObject> | |
| 14 | +- (void)loginSuccess:(CNLiveCompleteInfoView *)view result:(id _Nonnull)result; | |
| 15 | + | |
| 16 | +@end | |
| 17 | +@interface CNLiveCompleteInfoView : UIView | |
| 18 | +@property (nonatomic, weak) id<CNLiveUserInfoViewDelegate> delegate; | |
| 19 | + | |
| 20 | +@end | |
| 21 | + | |
| 22 | +NS_ASSUME_NONNULL_END | ... | ... |
CNLiveLoginModule/Classes/View/CNLiveCompleteInfoView.m
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveCompleteInfoView.m | |
| 3 | +// CNLiveLoginModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright (c) 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "CNLiveCompleteInfoView.h" | |
| 10 | +#import "CNLiveLoginTextField.h" | |
| 11 | +#import "YYKit.h" | |
| 12 | + | |
| 13 | +//#import "UIView+Layout.h" | |
| 14 | +//#import "UIImage+Bundle.h" | |
| 15 | +//#import "XWColorHeader.h" | |
| 16 | +//#import <XWUserCenter/XWUserCenter.h> | |
| 17 | +//#import "XWAlertView.h" | |
| 18 | +//#import "XWAlertController.h" | |
| 19 | + | |
| 20 | +//#import "NSString+Validation.h" | |
| 21 | +//#import <ZLPhotoBrowser/ZLPhotoBrowser.h> | |
| 22 | +//#import <ZLPhotoBrowser/ZLCustomCamera.h> | |
| 23 | +//#import "XWLoginNotification.h" | |
| 24 | + | |
| 25 | +@interface CNLiveCompleteInfoView()<UITextFieldDelegate>{ | |
| 26 | + UIImage *_image; | |
| 27 | +} | |
| 28 | + | |
| 29 | +@property (nonatomic, weak) UIButton *head; | |
| 30 | +@property (nonatomic, weak) CNLiveLoginTextField *nickname; | |
| 31 | +@property (nonatomic, weak) UIButton *next; | |
| 32 | + | |
| 33 | +@end | |
| 34 | +@implementation CNLiveCompleteInfoView | |
| 35 | +static NSInteger const rowHeight = 40; | |
| 36 | +static NSInteger const space = 40; | |
| 37 | + | |
| 38 | +- (instancetype)initWithFrame:(CGRect)frame{ | |
| 39 | + self = [super initWithFrame:frame]; | |
| 40 | + if (self) { | |
| 41 | + self.userInteractionEnabled = YES; | |
| 42 | + [self createSubviews:frame]; | |
| 43 | + _image = nil; | |
| 44 | + } | |
| 45 | + return self; | |
| 46 | + | |
| 47 | +} | |
| 48 | +- (void)createSubviews:(CGRect)frame{ | |
| 49 | + UIButton *head = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 50 | + head.frame = CGRectMake((frame.size.width-80)/2.0, 0, 80, 80); | |
| 51 | + head.layer.cornerRadius = 40; | |
| 52 | + head.layer.masksToBounds = YES; | |
| 53 | + head.adjustsImageWhenHighlighted = NO; | |
| 54 | + UIImage *image1 = [self xw_getImageName:@"login_camera" bundleName:@"CNLiveLoginModule" targetClass:[self class]]; | |
| 55 | + [head setImage:image1 forState:UIControlStateNormal]; | |
| 56 | + [head addTarget:self action:@selector(headDidClicked:) forControlEvents:UIControlEventTouchUpInside]; | |
| 57 | + [self addSubview:head]; | |
| 58 | + self.head = head; | |
| 59 | + | |
| 60 | + CNLiveLoginTextField *nickname = [[CNLiveLoginTextField alloc] initWithFrame:CGRectMake(0, head.bottom+space, frame.size.width, rowHeight)]; | |
| 61 | + nickname.keyboardType = UIKeyboardTypeNumberPad; | |
| 62 | +// if(User_Login&&[User_Tel isValidMobile]){ | |
| 63 | +// nickname.text = [User_Tel stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"]; | |
| 64 | +// } | |
| 65 | + | |
| 66 | + nickname.placeholder = @"请输入昵称"; | |
| 67 | + nickname.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]; | |
| 68 | + nickname.placeholderColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0]; | |
| 69 | + nickname.font = [UIFont systemFontOfSize:16]; | |
| 70 | + nickname.textAlignment = NSTextAlignmentLeft; | |
| 71 | + [nickname addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; | |
| 72 | + nickname.clearButtonMode = UITextFieldViewModeWhileEditing; | |
| 73 | + nickname.delegate = self; | |
| 74 | + [self addSubview:nickname]; | |
| 75 | + self.nickname = nickname; | |
| 76 | + | |
| 77 | + UIButton *next = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 78 | + next.frame = CGRectMake(nickname.left, nickname.bottom+space, nickname.width, rowHeight); | |
| 79 | + [next setTitle:@"下一步" forState:UIControlStateNormal]; | |
| 80 | + [next setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; | |
| 81 | + next.titleLabel.font = [UIFont systemFontOfSize:15.0]; | |
| 82 | + next.backgroundColor = [UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0]; | |
| 83 | + next.layer.cornerRadius = 20; | |
| 84 | + next.layer.masksToBounds = YES; | |
| 85 | + next.adjustsImageWhenHighlighted = NO; | |
| 86 | + [next addTarget:self action:@selector(nextDidClicked:) forControlEvents:UIControlEventTouchUpInside]; | |
| 87 | + [self addSubview:next]; | |
| 88 | + self.next = next; | |
| 89 | + | |
| 90 | +} | |
| 91 | +- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { | |
| 92 | + [self endEditing:YES]; | |
| 93 | + | |
| 94 | +} | |
| 95 | +#pragma mark - UITextFieldDelegate | |
| 96 | +- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ | |
| 97 | + if ([textField isEqual:_nickname]) { | |
| 98 | + return YES; | |
| 99 | + | |
| 100 | + } | |
| 101 | + else { | |
| 102 | + return YES; | |
| 103 | + | |
| 104 | + } | |
| 105 | +} | |
| 106 | + | |
| 107 | +- (void)textFieldDidChange:(UITextField *)textField { | |
| 108 | + if (![_nickname.text isEqualToString:@""]) { | |
| 109 | + _next.enabled = YES; | |
| 110 | + | |
| 111 | + } | |
| 112 | + else { | |
| 113 | + _next.enabled = NO; | |
| 114 | + | |
| 115 | + } | |
| 116 | + | |
| 117 | +} | |
| 118 | + | |
| 119 | +- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { | |
| 120 | + if ([textField isEqual:_nickname]) { | |
| 121 | + NSInteger maxTextLength = 20; | |
| 122 | + if(string.length == 0) { | |
| 123 | + //判断是不是删除键 | |
| 124 | + return YES; | |
| 125 | + } | |
| 126 | + else if(textField.text.length >= maxTextLength) { | |
| 127 | + NSLog(@"输入的字符个数大于20,忽略输入"); | |
| 128 | + return NO; | |
| 129 | + } | |
| 130 | + else if (textField.text.length + string.length > maxTextLength){ | |
| 131 | + NSInteger length = textField.text.length; | |
| 132 | + NSInteger needLen = maxTextLength - length; | |
| 133 | + textField.text = [textField.text stringByAppendingString:[string substringToIndex:needLen]]; | |
| 134 | + return NO; | |
| 135 | + } | |
| 136 | + else{ | |
| 137 | + return YES; | |
| 138 | + } | |
| 139 | + } | |
| 140 | + else{ | |
| 141 | + return YES; | |
| 142 | + } | |
| 143 | +} | |
| 144 | + | |
| 145 | +#pragma mark - Action | |
| 146 | +- (void)headDidClicked:(UIButton *)btn{ | |
| 147 | + btn.userInteractionEnabled = NO; | |
| 148 | +// NSArray *optionArray = @[@"从相册中选择",@"相机"]; | |
| 149 | +// XWActionSheetView *sheetView = [[XWActionSheetView alloc] initWithOptions:optionArray select:^(NSInteger index) { | |
| 150 | +// NSLog(@"%@",optionArray[index]); | |
| 151 | +// if(index == 0){ | |
| 152 | +// // 相册 | |
| 153 | +// ZLPhotoActionSheet *ac = [[ZLPhotoActionSheet alloc] init]; | |
| 154 | +// // 相册参数配置,configuration有默认值,可直接使用并对其属性进行修改 | |
| 155 | +// ac.configuration.maxSelectCount = 1; | |
| 156 | +// ac.configuration.maxPreviewCount = 10; | |
| 157 | +// //如调用的方法无sender参数,则该参数必传 | |
| 158 | +// ac.sender = (UIViewController *)self.delegate; | |
| 159 | +// __weak typeof(self) weakSelf = self; | |
| 160 | +// [ac setSelectImageBlock:^(NSArray<UIImage *> * _Nonnull images, NSArray<PHAsset *> * _Nonnull assets, BOOL isOriginal) { | |
| 161 | +// __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 162 | +// if(!strongSelf) return; | |
| 163 | +// strongSelf->_image = images[0]; | |
| 164 | +// [strongSelf.head setImage:images[0] forState:UIControlStateNormal]; | |
| 165 | +// | |
| 166 | +// }]; | |
| 167 | +// [ac showPreviewAnimated:YES]; | |
| 168 | +// | |
| 169 | +// }else if (index == 1){ | |
| 170 | +// // 相机 | |
| 171 | +// ZLCustomCamera *camera = [[ZLCustomCamera alloc] init]; | |
| 172 | +// camera.allowTakePhoto = YES; | |
| 173 | +// __weak typeof(self) weakSelf = self; | |
| 174 | +// camera.doneBlock = ^(UIImage *image, NSURL *videoUrl) { | |
| 175 | +// __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 176 | +// if(!strongSelf) return; | |
| 177 | +// strongSelf->_image = image; | |
| 178 | +// [strongSelf.head setImage:image forState:UIControlStateNormal]; | |
| 179 | +// | |
| 180 | +// }; | |
| 181 | +// [(UIViewController *)self.delegate showDetailViewController:camera sender:nil]; | |
| 182 | +// } | |
| 183 | +// btn.userInteractionEnabled = YES; | |
| 184 | +// | |
| 185 | +// } cancel:^{ | |
| 186 | +// btn.userInteractionEnabled = YES; | |
| 187 | +// NSLog(@"取消"); | |
| 188 | +// | |
| 189 | +// }]; | |
| 190 | +// [sheetView show]; | |
| 191 | +// XWAlertController *alertController = [XWAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:XWAlertControllerStyleActionSheet]; | |
| 192 | +// alertController.needDialogBlur = NO; | |
| 193 | +// XWAlertAction *action1 = [XWAlertAction actionWithTitle:@"从相册中选择" style:XWAlertActionStyleDefault handler:^(XWAlertAction * _Nonnull action) { | |
| 194 | +// ZLPhotoActionSheet *ac = [[ZLPhotoActionSheet alloc] init]; | |
| 195 | +// // 相册参数配置,configuration有默认值,可直接使用并对其属性进行修改 | |
| 196 | +// ac.configuration.maxSelectCount = 1; | |
| 197 | +// ac.configuration.maxPreviewCount = 10; | |
| 198 | +// //如调用的方法无sender参数,则该参数必传 | |
| 199 | +// ac.sender = (UIViewController *)self.delegate; | |
| 200 | +// __weak typeof(self) weakSelf = self; | |
| 201 | +// [ac setSelectImageBlock:^(NSArray<UIImage *> * _Nonnull images, NSArray<PHAsset *> * _Nonnull assets, BOOL isOriginal) { | |
| 202 | +// __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 203 | +// if(!strongSelf) return; | |
| 204 | +// strongSelf->_image = images[0]; | |
| 205 | +// [strongSelf.head setImage:images[0] forState:UIControlStateNormal]; | |
| 206 | +// | |
| 207 | +// }]; | |
| 208 | +// [ac showPreviewAnimated:YES]; | |
| 209 | +// btn.userInteractionEnabled = YES; | |
| 210 | +// }]; | |
| 211 | +// XWAlertAction *action2 = [XWAlertAction actionWithTitle:@"相机" style:XWAlertActionStyleDefault handler:^(XWAlertAction * _Nonnull action) { | |
| 212 | +// // 相机 | |
| 213 | +// ZLCustomCamera *camera = [[ZLCustomCamera alloc] init]; | |
| 214 | +// camera.allowTakePhoto = YES; | |
| 215 | +// __weak typeof(self) weakSelf = self; | |
| 216 | +// camera.doneBlock = ^(UIImage *image, NSURL *videoUrl) { | |
| 217 | +// __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 218 | +// if(!strongSelf) return; | |
| 219 | +// strongSelf->_image = image; | |
| 220 | +// [strongSelf.head setImage:image forState:UIControlStateNormal]; | |
| 221 | +// | |
| 222 | +// }; | |
| 223 | +// [(UIViewController *)weakSelf.delegate presentViewController:camera animated:YES completion:nil]; | |
| 224 | +// btn.userInteractionEnabled = YES; | |
| 225 | +// }]; | |
| 226 | +// | |
| 227 | +// XWAlertAction *action3 = [XWAlertAction actionWithTitle:@"取消" style:XWAlertActionStyleCancel handler:^(XWAlertAction * _Nonnull action) { | |
| 228 | +// btn.userInteractionEnabled = YES; | |
| 229 | +// }]; | |
| 230 | +// [alertController addAction:action1]; | |
| 231 | +// [alertController addAction:action3]; // 取消按钮一定排在最底部 | |
| 232 | +// [alertController addAction:action2]; | |
| 233 | +// [(UIViewController *)self.delegate presentViewController:alertController animated:YES completion:^{}]; | |
| 234 | + | |
| 235 | +} | |
| 236 | +- (void)nextDidClicked:(UIButton *)btn{ | |
| 237 | + [_nickname resignFirstResponder]; | |
| 238 | + if ([_nickname.text isEqualToString:@""]) { | |
| 239 | +// [XWAlertView alertViewWithFlexTextMessage:@"请输入昵称" view:self.superview]; | |
| 240 | + return; | |
| 241 | + } | |
| 242 | + btn.userInteractionEnabled = NO; | |
| 243 | + [self.superview endEditing:YES]; | |
| 244 | + /** | |
| 245 | + * 修改昵称和头像 | |
| 246 | + **/ | |
| 247 | + __weak typeof(self) weakSelf = self; | |
| 248 | +// [XWUserRequest updateUserInfoWithUid:User_ID name:_nickname.text head:_image success:^(id _Nonnull result) { | |
| 249 | +// btn.userInteractionEnabled = YES; | |
| 250 | +// __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 251 | +// if(!strongSelf) return; | |
| 252 | +// if (strongSelf.delegate && [strongSelf.delegate respondsToSelector:@selector(loginSuccess:result:)]) { | |
| 253 | +// [strongSelf.delegate loginSuccess:strongSelf result:result]; | |
| 254 | +// | |
| 255 | +// } | |
| 256 | +// | |
| 257 | +// } failure:^(NSDictionary * _Nonnull errorDic) { | |
| 258 | +// btn.userInteractionEnabled = YES; | |
| 259 | +// __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 260 | +// if(!strongSelf) return; | |
| 261 | +// [XWAlertView alertErrorViewWithTextMessage:@"登录失败"]; | |
| 262 | +// }]; | |
| 263 | + | |
| 264 | +} | |
| 265 | + | |
| 266 | +/* | |
| 267 | +// Only override drawRect: if you perform custom drawing. | |
| 268 | +// An empty implementation adversely affects performance during animation. | |
| 269 | +- (void)drawRect:(CGRect)rect { | |
| 270 | + // Drawing code | |
| 271 | +} | |
| 272 | +*/ | |
| 273 | + | |
| 274 | +/** | |
| 275 | + * 创建图片 | |
| 276 | + * | |
| 277 | + * @param imageName 图片名字 | |
| 278 | + * @param bundleName 图片所在的bundle名字 | |
| 279 | + * @param targetClass 类和bundle的同级目录 | |
| 280 | + * @return 返回UIImage | |
| 281 | + */ | |
| 282 | +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{ | |
| 283 | + NSBundle *bundle = [NSBundle bundleForClass:targetClass]; | |
| 284 | + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"]; | |
| 285 | + NSBundle *targetBundle = [NSBundle bundleWithURL:url]; | |
| 286 | + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil]; | |
| 287 | + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil]; | |
| 288 | +} | |
| 289 | + | |
| 290 | +@end | ... | ... |
CNLiveLoginModule/Classes/View/CNLiveCountDownButton.h
0 → 100644
| 1 | +// | |
| 2 | +// XWCountDownButton.h | |
| 3 | +// CNLiveLoginModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright (c) 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 倒计时按钮 | |
| 11 | + */ | |
| 12 | +#import <UIKit/UIKit.h> | |
| 13 | + | |
| 14 | +NS_ASSUME_NONNULL_BEGIN | |
| 15 | + | |
| 16 | +@class CNLiveCountDownButton; | |
| 17 | + | |
| 18 | +@protocol CNLiveCountDownButtonDataSource <NSObject> | |
| 19 | +// 设置起始倒计时秒数 | |
| 20 | +- (NSInteger)startCountDownNumOfCountDownButton:(CNLiveCountDownButton *)button; | |
| 21 | + | |
| 22 | +@end | |
| 23 | + | |
| 24 | +@protocol CNLiveCountDownButtonDelegate <NSObject> | |
| 25 | +// 倒计时按钮点击时回调 | |
| 26 | +- (void)countDownButtonDidClick:(CNLiveCountDownButton *)button; | |
| 27 | +// 倒计时进行中的回调 | |
| 28 | +- (void)countDownButtonDidCountDown:(CNLiveCountDownButton *)button countDownNum:(NSInteger)countDownNum; | |
| 29 | +// 倒计时结束时的回调 | |
| 30 | +- (void)countDownButtonDidEndCountDown:(CNLiveCountDownButton *)button; | |
| 31 | + | |
| 32 | +@end | |
| 33 | + | |
| 34 | +@interface CNLiveCountDownButton : UIButton | |
| 35 | + | |
| 36 | +@property (nonatomic, weak) id <CNLiveCountDownButtonDataSource> dataSource; | |
| 37 | +@property (nonatomic, weak) id <CNLiveCountDownButtonDelegate> delegate; | |
| 38 | + | |
| 39 | +/** 开始倒计时 */ | |
| 40 | +- (void)startCountDown; | |
| 41 | +/** 释放timer */ | |
| 42 | +- (void)releaseTimer; | |
| 43 | + | |
| 44 | +@end | |
| 45 | + | |
| 46 | +NS_ASSUME_NONNULL_END | ... | ... |
CNLiveLoginModule/Classes/View/CNLiveCountDownButton.m
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveCountDownButton.m | |
| 3 | +// CNLiveLoginModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright (c) 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "CNLiveCountDownButton.h" | |
| 10 | +@interface CNLiveCountDownButton() | |
| 11 | +@property (nonatomic, strong) NSTimer *timer; | |
| 12 | + | |
| 13 | +@end | |
| 14 | + | |
| 15 | +@implementation CNLiveCountDownButton{ | |
| 16 | + // 剩余倒计时 | |
| 17 | + NSInteger _countDownNum; | |
| 18 | +} | |
| 19 | + | |
| 20 | +- (instancetype)initWithFrame:(CGRect)frame { | |
| 21 | + if (self = [super initWithFrame:frame]) { | |
| 22 | + [self addTarget:self action:@selector(onClick) forControlEvents:UIControlEventTouchUpInside]; | |
| 23 | + } | |
| 24 | + return self; | |
| 25 | +} | |
| 26 | + | |
| 27 | +// 按钮点击 | |
| 28 | +- (void)onClick { | |
| 29 | + if ([self.dataSource respondsToSelector:@selector(startCountDownNumOfCountDownButton:)]) { | |
| 30 | + _countDownNum = [self.dataSource startCountDownNumOfCountDownButton:self]; | |
| 31 | + } | |
| 32 | + if ([self.delegate respondsToSelector:@selector(countDownButtonDidClick:)]) { | |
| 33 | + [self.delegate countDownButtonDidClick:self]; | |
| 34 | + } | |
| 35 | +} | |
| 36 | + | |
| 37 | +// 开始倒计时 | |
| 38 | +- (void)startCountDown { | |
| 39 | + if (self.timer) { | |
| 40 | + [self releaseTimer]; | |
| 41 | + } | |
| 42 | + | |
| 43 | + self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(refreshButton) userInfo:nil repeats:YES]; | |
| 44 | + [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes]; | |
| 45 | +} | |
| 46 | + | |
| 47 | +// 刷新按钮 | |
| 48 | +- (void)refreshButton { | |
| 49 | + _countDownNum --; | |
| 50 | + | |
| 51 | + if ([self.delegate respondsToSelector:@selector(countDownButtonDidCountDown:countDownNum:)]) { | |
| 52 | + [self.delegate countDownButtonDidCountDown:self countDownNum:_countDownNum]; | |
| 53 | + } | |
| 54 | + | |
| 55 | + if (_countDownNum == 0) { | |
| 56 | + [self releaseTimer]; | |
| 57 | + if ([self.delegate respondsToSelector:@selector(countDownButtonDidEndCountDown:)]) { | |
| 58 | + [self.delegate countDownButtonDidEndCountDown:self]; | |
| 59 | + } | |
| 60 | + } | |
| 61 | +} | |
| 62 | + | |
| 63 | +- (void)releaseTimer { | |
| 64 | + if (self.timer) { | |
| 65 | + [self.timer invalidate]; | |
| 66 | + self.timer = nil; | |
| 67 | + } | |
| 68 | +} | |
| 69 | + | |
| 70 | +- (void)dealloc { | |
| 71 | + NSLog(@"倒计时按钮已释放"); | |
| 72 | +} | |
| 73 | + | |
| 74 | +@end | ... | ... |
CNLiveLoginModule/Classes/View/CNLiveLoginCountryView.h
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveLoginCountryView.h | |
| 3 | +// CNLiveLoginModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright (c) 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <UIKit/UIKit.h> | |
| 10 | + | |
| 11 | +NS_ASSUME_NONNULL_BEGIN | |
| 12 | +@protocol CNLiveLoginCountryViewDelegate <NSObject> | |
| 13 | +- (void)selectCountryName:(NSString *)countryName countryCode:(NSString *)countryCode; | |
| 14 | + | |
| 15 | +@end | |
| 16 | +@interface CNLiveLoginCountryView : UIView | |
| 17 | +@property (nonatomic, weak) id<CNLiveLoginCountryViewDelegate> delegate; | |
| 18 | + | |
| 19 | +@end | |
| 20 | + | |
| 21 | +NS_ASSUME_NONNULL_END | ... | ... |
CNLiveLoginModule/Classes/View/CNLiveLoginCountryView.m
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveLoginCountryView.m | |
| 3 | +// CNLiveLoginModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright (c) 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "CNLiveLoginCountryView.h" | |
| 10 | +#import "YYKit.h" | |
| 11 | + | |
| 12 | +//#import "UIImage+Bundle.h" | |
| 13 | +//#import "UIView+Layout.h" | |
| 14 | +//#import "XWColorHeader.h" | |
| 15 | +//#import "XWSelectCountryViewController.h" | |
| 16 | +#import "CNLiveChooseCountryController.h" | |
| 17 | + | |
| 18 | +@interface CNLiveLoginCountryView()<ChooseCountriesDelegate> | |
| 19 | +{ | |
| 20 | + NSString *_countryName; | |
| 21 | + NSString *_countryCode; | |
| 22 | +} | |
| 23 | +@property (nonatomic, weak) UILabel *name; | |
| 24 | +@property (nonatomic, weak) UIButton *code; | |
| 25 | + | |
| 26 | +@end | |
| 27 | +@implementation CNLiveLoginCountryView | |
| 28 | + | |
| 29 | +- (instancetype)initWithFrame:(CGRect)frame{ | |
| 30 | + self = [super initWithFrame:frame]; | |
| 31 | + if (self) { | |
| 32 | + _countryName = @"中国大陆"; | |
| 33 | + _countryCode = @"86"; | |
| 34 | + [self createSubviews:frame]; | |
| 35 | + } | |
| 36 | + return self; | |
| 37 | + | |
| 38 | +} | |
| 39 | +- (void)createSubviews:(CGRect)frame{ | |
| 40 | + UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width-70, frame.size.height)]; | |
| 41 | + name.textColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0]; | |
| 42 | + name.font = [UIFont systemFontOfSize:16]; | |
| 43 | + name.textAlignment = NSTextAlignmentLeft; | |
| 44 | + name.text = _countryName; | |
| 45 | + [self addSubview:name]; | |
| 46 | + self.name = name; | |
| 47 | + | |
| 48 | + UIButton *code = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 49 | + code.frame = CGRectMake(name.right, 0, 70, frame.size.height); | |
| 50 | + [code setTitle:[NSString stringWithFormat:@"+%@",_countryCode] forState:UIControlStateNormal]; | |
| 51 | + [code setTitleColor:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0] forState:UIControlStateNormal]; | |
| 52 | + code.titleLabel.font = [UIFont systemFontOfSize:14]; | |
| 53 | + UIImage *image = [self xw_getImageName:@"login_country" bundleName:@"CNLiveLoginModule" targetClass:[self class]]; | |
| 54 | + [code setImage:image forState:UIControlStateNormal]; | |
| 55 | + code.adjustsImageWhenHighlighted = NO; | |
| 56 | + //button图片的偏移量,距上左下右分别(0, 0, 0, 0)像素点 | |
| 57 | + code.imageEdgeInsets = UIEdgeInsetsMake(0, 60, 0, 0); | |
| 58 | + //button标题的偏移量,这个偏移量是相对于图片的 | |
| 59 | + code.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10); | |
| 60 | + [code addTarget:self action:@selector(countryCodeDidClicked:) forControlEvents:UIControlEventTouchUpInside]; | |
| 61 | + [self addSubview:code]; | |
| 62 | + self.code = code; | |
| 63 | + | |
| 64 | +} | |
| 65 | + | |
| 66 | +/* | |
| 67 | +// Only override drawRect: if you perform custom drawing. | |
| 68 | +// An empty implementation adversely affects performance during animation. | |
| 69 | +- (void)drawRect:(CGRect)rect { | |
| 70 | + // Drawing code | |
| 71 | +} | |
| 72 | +*/ | |
| 73 | +#pragma mark - Action | |
| 74 | +- (void)countryCodeDidClicked:(UIButton *)btn{ | |
| 75 | + UIViewController *root = [UIApplication sharedApplication].delegate.window.rootViewController; | |
| 76 | + CNLiveChooseCountryController *vc = [[CNLiveChooseCountryController alloc] init]; | |
| 77 | + vc.delegate = self; | |
| 78 | + [root presentViewController:vc animated:YES completion:nil]; | |
| 79 | + | |
| 80 | +} | |
| 81 | + | |
| 82 | +#pragma mark - XWSelectCountryViewDelegate | |
| 83 | +- (void)chooseViewController:(CNLiveChooseCountryController *)controller countryName:(NSString *)name countryCode:(NSString *)code{ | |
| 84 | + if(![_countryName isEqualToString:name]&&![_countryCode isEqualToString:code]){ | |
| 85 | + _countryName = name; | |
| 86 | + _countryCode = code; | |
| 87 | + _name.text = name; | |
| 88 | + [_code setTitle:[NSString stringWithFormat:@"+%@",code] forState:UIControlStateNormal]; | |
| 89 | + } | |
| 90 | + if (self.delegate && [self.delegate respondsToSelector:@selector(selectCountryName:countryCode:)]) { | |
| 91 | + [self.delegate selectCountryName:name countryCode:code]; | |
| 92 | + } | |
| 93 | +} | |
| 94 | + | |
| 95 | +/** | |
| 96 | + * 创建图片 | |
| 97 | + * | |
| 98 | + * @param imageName 图片名字 | |
| 99 | + * @param bundleName 图片所在的bundle名字 | |
| 100 | + * @param targetClass 类和bundle的同级目录 | |
| 101 | + * @return 返回UIImage | |
| 102 | + */ | |
| 103 | +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{ | |
| 104 | + NSBundle *bundle = [NSBundle bundleForClass:targetClass]; | |
| 105 | + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"]; | |
| 106 | + NSBundle *targetBundle = [NSBundle bundleWithURL:url]; | |
| 107 | + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil]; | |
| 108 | + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil]; | |
| 109 | +} | |
| 110 | + | |
| 111 | +@end | ... | ... |
CNLiveLoginModule/Classes/View/CNLiveLoginHeaderView.m deleted
100644 → 0
| 1 | -// | |
| 2 | -// CNLiveLoginHeaderView.m | |
| 3 | -// CNLiveMineModule | |
| 4 | -// | |
| 5 | -// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | -// Copyright © 2019 153993236@qq.com. All rights reserved. | |
| 7 | -// | |
| 8 | - | |
| 9 | -#import "CNLiveLoginHeaderView.h" | |
| 10 | -#import <Masonry/Masonry.h> | |
| 11 | -#import <SDWebImage/SDWebImage.h> | |
| 12 | -#import "QMUIKit.h" | |
| 13 | - | |
| 14 | -#define HexColor(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] | |
| 15 | - | |
| 16 | -@interface CNLiveLoginHeaderView () | |
| 17 | -@property (nonatomic, strong) UIImageView *bgView; | |
| 18 | -@property (nonatomic, strong) UIButton *witness; | |
| 19 | - | |
| 20 | -@property (nonatomic, strong) UIImageView *header; | |
| 21 | -@property (nonatomic, strong) UILabel *name; | |
| 22 | -@property (nonatomic, strong) UILabel *certification; | |
| 23 | -@property (nonatomic, strong) UILabel *address; | |
| 24 | -@property (nonatomic, strong) UIButton *sign; | |
| 25 | - | |
| 26 | -@end | |
| 27 | - | |
| 28 | -@implementation CNLiveLoginHeaderView | |
| 29 | -static const NSInteger margin = 20; | |
| 30 | - | |
| 31 | -- (instancetype)initWithFrame:(CGRect)frame{ | |
| 32 | - self = [super initWithFrame:frame]; | |
| 33 | - if(self){ | |
| 34 | - self.userInteractionEnabled = YES; | |
| 35 | - self.backgroundColor = HexColor(0xf4f4f4); | |
| 36 | - [self createSubViews]; | |
| 37 | - } | |
| 38 | - return self; | |
| 39 | -} | |
| 40 | - | |
| 41 | -- (void)dealloc { | |
| 42 | - NSLog(@"CNLiveLoginHeaderView -- dealloc"); | |
| 43 | - | |
| 44 | -} | |
| 45 | - | |
| 46 | -- (void)createSubViews { | |
| 47 | - [self addSubview:self.bgView]; | |
| 48 | - [self addSubview:self.witness]; | |
| 49 | - | |
| 50 | - [self addSubview:self.header]; | |
| 51 | - [self addSubview:self.name]; | |
| 52 | - [self addSubview:self.certification]; | |
| 53 | - [self addSubview:self.address]; | |
| 54 | - [self addSubview:self.sign]; | |
| 55 | - | |
| 56 | -} | |
| 57 | - | |
| 58 | -- (void)layoutSubviews{ | |
| 59 | - [super layoutSubviews]; | |
| 60 | - [_witness mas_remakeConstraints:^(MASConstraintMaker *make) { | |
| 61 | - make.left.equalTo(self.mas_left).with.offset(1.5*margin); | |
| 62 | - make.right.equalTo(self.mas_right).with.offset(-1.5*margin); | |
| 63 | - make.width.height.offset(60); | |
| 64 | - make.bottom.equalTo(self.mas_bottom).with.offset(-0.5*margin); | |
| 65 | - | |
| 66 | - }]; | |
| 67 | - | |
| 68 | - [_bgView mas_remakeConstraints:^(MASConstraintMaker *make) { | |
| 69 | - make.left.equalTo(self.mas_left).with.offset(0); | |
| 70 | - make.right.equalTo(self.mas_right).with.offset(-0); | |
| 71 | - make.top.equalTo(self.mas_top).with.offset(0); | |
| 72 | - make.bottom.equalTo(self.witness.mas_centerY).with.offset(0.5*margin); | |
| 73 | - | |
| 74 | - }]; | |
| 75 | - | |
| 76 | - [_header mas_remakeConstraints:^(MASConstraintMaker *make) { | |
| 77 | - make.left.equalTo(self.mas_left).with.offset(margin); | |
| 78 | - make.centerY.equalTo(self.bgView.mas_centerY).with.offset(0); | |
| 79 | - make.width.height.offset(60); | |
| 80 | - | |
| 81 | - }]; | |
| 82 | - | |
| 83 | - [_certification mas_remakeConstraints:^(MASConstraintMaker *make) { | |
| 84 | - make.centerY.equalTo(self.header.mas_centerY); | |
| 85 | - make.left.equalTo(self.header.mas_right).with.offset(margin/2.0); | |
| 86 | - make.height.offset(30); | |
| 87 | - | |
| 88 | - }]; | |
| 89 | - | |
| 90 | - [_name mas_remakeConstraints:^(MASConstraintMaker *make) { | |
| 91 | - make.bottom.equalTo(self.certification.mas_top); | |
| 92 | - make.left.equalTo(self.certification.mas_left); | |
| 93 | - make.right.equalTo(self.bgView.mas_right).with.offset(-margin); | |
| 94 | - make.height.equalTo(self.certification.mas_height); | |
| 95 | - | |
| 96 | - }]; | |
| 97 | - | |
| 98 | - [_address mas_remakeConstraints:^(MASConstraintMaker *make) { | |
| 99 | - make.top.equalTo(self.certification.mas_bottom); | |
| 100 | - make.left.equalTo(self.name.mas_left); | |
| 101 | - make.right.equalTo(self.name.mas_right); | |
| 102 | - make.height.equalTo(self.name.mas_height); | |
| 103 | - | |
| 104 | - }]; | |
| 105 | - | |
| 106 | - [_sign mas_remakeConstraints:^(MASConstraintMaker *make) { | |
| 107 | - make.right.equalTo(self.mas_right).with.offset(0); | |
| 108 | - make.centerY.equalTo(self.header.mas_centerY).with.offset(0); | |
| 109 | - make.width.mas_equalTo(105); | |
| 110 | - make.height.mas_equalTo(32); | |
| 111 | - | |
| 112 | - }]; | |
| 113 | -} | |
| 114 | -/* | |
| 115 | - // Only override drawRect: if you perform custom drawing. | |
| 116 | - // An empty implementation adversely affects performance during animation. | |
| 117 | - - (void)drawRect:(CGRect)rect { | |
| 118 | - // Drawing code | |
| 119 | - } | |
| 120 | - */ | |
| 121 | -#pragma mark - Private Methods | |
| 122 | -- (NSMutableAttributedString *)createAttributedImageName:(NSString *)imageName string:(NSString *)string isFront:(BOOL)isFront{ | |
| 123 | - if(isFront){ | |
| 124 | - string = [NSString stringWithFormat:@" %@",string]; | |
| 125 | - } | |
| 126 | - // 1.创建一个富文本 | |
| 127 | - NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:string]; | |
| 128 | - // 修改富文本中的不同文字的样式 | |
| 129 | -// [attri addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, string.length)]; | |
| 130 | -// [attri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, string.length)]; | |
| 131 | - // 2.添加表情图片 | |
| 132 | - NSTextAttachment *attch = [[NSTextAttachment alloc] init]; | |
| 133 | - // 表情图片 | |
| 134 | - UIImage *xw_image = [self xw_getImageName:imageName bundleName:@"CNLiveMineModule" targetClass:[CNLiveLoginHeaderView class]]; | |
| 135 | - attch.image = xw_image; | |
| 136 | - if(isFront){ | |
| 137 | - // 设置图片大小 | |
| 138 | - attch.bounds = CGRectMake(0, -1.5, 10, 12); | |
| 139 | - // 创建带有图片的富文本 | |
| 140 | - NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch]; | |
| 141 | - [attri insertAttributedString:str atIndex:0];// 插入某个位置 | |
| 142 | - }else{ | |
| 143 | - // 设置图片大小 | |
| 144 | - attch.bounds = CGRectMake(10, -2, 15, 15); | |
| 145 | - // 创建带有图片的富文本 | |
| 146 | - NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch]; | |
| 147 | - [attri insertAttributedString:str atIndex:string.length];// 插入某个位置 | |
| 148 | - | |
| 149 | - } | |
| 150 | - return attri; | |
| 151 | - | |
| 152 | -} | |
| 153 | -- (NSMutableAttributedString *)createAttributedImages:(NSArray *)images { | |
| 154 | - // 1.创建一个富文本 | |
| 155 | - NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@""]; | |
| 156 | - for(NSString *image in images){ | |
| 157 | - // 2.添加表情图片 | |
| 158 | - NSTextAttachment *attch = [[NSTextAttachment alloc] init]; | |
| 159 | - // 表情图片 | |
| 160 | - UIImage *xw_image = [self xw_getImageName:image bundleName:@"CNLiveMineModule" targetClass:[CNLiveLoginHeaderView class]]; | |
| 161 | - attch.image = xw_image; | |
| 162 | - // 创建带有图片的富文本 | |
| 163 | - NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch]; | |
| 164 | - NSAttributedString *space = [[NSAttributedString alloc]initWithString:@" "]; | |
| 165 | - | |
| 166 | - [attri insertAttributedString:space atIndex:0]; | |
| 167 | - [attri insertAttributedString:str atIndex:0];// 插入某个位置 | |
| 168 | - | |
| 169 | - } | |
| 170 | - return attri; | |
| 171 | - | |
| 172 | -} | |
| 173 | - | |
| 174 | -#pragma mark - 懒加载 | |
| 175 | -- (UIButton *)witness { | |
| 176 | - if (!_witness) { | |
| 177 | - _witness = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 178 | - UIImage *xw_image = [self xw_getImageName:@"mine_observer" bundleName:@"CNLiveMineModule" targetClass:[CNLiveLoginHeaderView class]]; | |
| 179 | - _witness.imageView.contentMode = UIViewContentModeScaleAspectFit; | |
| 180 | - [_witness setImage:xw_image forState:UIControlStateNormal]; | |
| 181 | - _witness.adjustsImageWhenHighlighted = NO; | |
| 182 | - [_witness addTarget:self action:@selector(witnessDidClicked:) forControlEvents:UIControlEventTouchUpInside]; | |
| 183 | - } | |
| 184 | - return _witness; | |
| 185 | -} | |
| 186 | -- (UIImageView *)bgView { | |
| 187 | - if (!_bgView) { | |
| 188 | - _bgView = [[UIImageView alloc] init]; | |
| 189 | - _bgView.userInteractionEnabled = YES; | |
| 190 | - UIImage *xw_image = [self xw_getImageName:@"mine_bg" bundleName:@"CNLiveMineModule" targetClass:[CNLiveLoginHeaderView class]]; | |
| 191 | - _bgView.image = xw_image; | |
| 192 | - } | |
| 193 | - return _bgView; | |
| 194 | -} | |
| 195 | -- (UIImageView *)header { | |
| 196 | - if (!_header) { | |
| 197 | - _header = [[UIImageView alloc] init]; | |
| 198 | - _header.userInteractionEnabled = YES; | |
| 199 | - _header.layer.masksToBounds = YES; | |
| 200 | - _header.layer.cornerRadius = 30; | |
| 201 | - UIImage *xw_image = [self xw_getImageName:@"default_avatar_y" bundleName:@"CNLiveMineModule" targetClass:[CNLiveLoginHeaderView class]]; | |
| 202 | - [_header sd_setImageWithURL:[NSURL URLWithString:@"头像"] placeholderImage:xw_image]; | |
| 203 | - __weak typeof(self) weakSelf = self; | |
| 204 | -// [_header addGestureTapEventHandle:^(id _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) { | |
| 205 | -// __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 206 | -// if(!strongSelf) return ; | |
| 207 | -// if (strongSelf.delegate && [strongSelf.delegate respondsToSelector:@selector(headerView:pushToController:)]) { | |
| 208 | -// [strongSelf.delegate headerView:strongSelf pushToController:CNLiveMineHeaderViewTypeUerInfo]; | |
| 209 | -// } | |
| 210 | -// }]; | |
| 211 | - } | |
| 212 | - return _header; | |
| 213 | -} | |
| 214 | - | |
| 215 | -- (UILabel *)name { | |
| 216 | - if (!_name) { | |
| 217 | - _name = [[UILabel alloc] init]; | |
| 218 | - _name.userInteractionEnabled = YES; | |
| 219 | - _name.numberOfLines = 1; | |
| 220 | - _name.textColor = [UIColor whiteColor]; | |
| 221 | - _name.font = [UIFont systemFontOfSize:16]; | |
| 222 | - _name.attributedText = [self createAttributedImageName:@"mine_code" string:@"张晓文" isFront:NO]; | |
| 223 | - __weak typeof(self) weakSelf = self; | |
| 224 | -// [_name addGestureTapEventHandle:^(id _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) { | |
| 225 | -// __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 226 | -// if(!strongSelf) return ; | |
| 227 | -// if (strongSelf.delegate && [strongSelf.delegate respondsToSelector:@selector(headerView:pushToController:)]) { | |
| 228 | -// [strongSelf.delegate headerView:strongSelf pushToController:CNLiveMineHeaderViewTypeCode]; | |
| 229 | -// } | |
| 230 | -// }]; | |
| 231 | - | |
| 232 | - } | |
| 233 | - return _name; | |
| 234 | -} | |
| 235 | -- (UILabel *)certification { | |
| 236 | - if (!_certification) { | |
| 237 | - _certification = [[UILabel alloc] init]; | |
| 238 | - _certification.numberOfLines = 1; | |
| 239 | - _certification.textColor = [UIColor whiteColor]; | |
| 240 | - _certification.font = [UIFont systemFontOfSize:16]; | |
| 241 | - _certification.attributedText = [self createAttributedImages:@[@"mine_overbadge",@"mine_common", @"mine_wjj_certification"]]; | |
| 242 | - } | |
| 243 | - return _certification; | |
| 244 | -} | |
| 245 | -- (UILabel *)address { | |
| 246 | - if (!_address) { | |
| 247 | - _address = [[UILabel alloc] init]; | |
| 248 | - _address.numberOfLines = 1; | |
| 249 | - _address.textColor = [UIColor colorWithRed:140/255.0 green:140/255.0 blue:142/255.0 alpha:1.0]; | |
| 250 | - _address.font = [UIFont systemFontOfSize:14]; | |
| 251 | - _address.attributedText = [self createAttributedImageName:@"mine_location" string:@"北京海淀区花园桥地铁站中外文大厦10层" isFront:YES]; | |
| 252 | - } | |
| 253 | - return _address; | |
| 254 | -} | |
| 255 | -- (UIButton *)sign { | |
| 256 | - if (!_sign) { | |
| 257 | - _sign = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 258 | - _sign.frame = CGRectMake(0, 0, 105, 32); | |
| 259 | - _sign.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.2]; | |
| 260 | - [_sign setTitle:@"签到赚积分" forState:UIControlStateNormal]; | |
| 261 | - _sign.titleLabel.font = [UIFont systemFontOfSize:13.0]; | |
| 262 | - [_sign setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; | |
| 263 | - UIImage *xw_image = [self xw_getImageName:@"sign_in_soccer" bundleName:@"CNLiveMineModule" targetClass:[CNLiveLoginHeaderView class]]; | |
| 264 | - [_sign setImage:xw_image forState:UIControlStateNormal]; | |
| 265 | - [_sign addTarget:self action:@selector(signDidClicked:) forControlEvents:UIControlEventTouchUpInside]; | |
| 266 | - UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_sign.layer.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(16, 16)]; | |
| 267 | - CAShapeLayer *maskLayer = [CAShapeLayer layer]; | |
| 268 | - maskLayer.frame = _sign.bounds; | |
| 269 | - maskLayer.path = maskPath.CGPath; | |
| 270 | - _sign.layer.mask = maskLayer; | |
| 271 | - } | |
| 272 | - return _sign; | |
| 273 | -} | |
| 274 | - | |
| 275 | -#pragma mark - 响应方法 | |
| 276 | -- (void)signDidClicked:(UIButton *)btn{ | |
| 277 | - | |
| 278 | -} | |
| 279 | - | |
| 280 | -- (void)witnessDidClicked:(UIButton *)btn{ | |
| 281 | - | |
| 282 | -} | |
| 283 | - | |
| 284 | -/** | |
| 285 | - * 创建图片 | |
| 286 | - * | |
| 287 | - * @param imageName 图片名字 | |
| 288 | - * @param bundleName 图片所在的bundle名字 | |
| 289 | - * @param targetClass 类和bundle的同级目录 | |
| 290 | - * @return 返回UIImage | |
| 291 | - */ | |
| 292 | -- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{ | |
| 293 | - NSBundle *bundle = [NSBundle bundleForClass:targetClass]; | |
| 294 | - NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"]; | |
| 295 | - NSBundle *targetBundle = [NSBundle bundleWithURL:url]; | |
| 296 | - UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil]; | |
| 297 | - return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil]; | |
| 298 | - | |
| 299 | -} | |
| 300 | - | |
| 301 | -@end |
CNLiveLoginModule/Classes/View/CNLiveLoginTextField.h
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveLoginTextField.h | |
| 3 | +// CNLiveLoginModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright (c) 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <UIKit/UIKit.h> | |
| 10 | + | |
| 11 | +NS_ASSUME_NONNULL_BEGIN | |
| 12 | + | |
| 13 | +@interface CNLiveLoginTextField : UITextField | |
| 14 | +@property (nonatomic, strong) UIColor *lineColor; | |
| 15 | +@property (nonatomic, strong) UIColor *placeholderColor; | |
| 16 | + | |
| 17 | +@end | |
| 18 | + | |
| 19 | +NS_ASSUME_NONNULL_END | ... | ... |
CNLiveLoginModule/Classes/View/CNLiveLoginTextField.m
0 → 100644
| 1 | +// | |
| 2 | +// XWLoginTextField.m | |
| 3 | +// CNLiveLoginModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright (c) 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "CNLiveLoginTextField.h" | |
| 10 | +#import <objc/runtime.h> | |
| 11 | +//#import "XWColorHeader.h" | |
| 12 | + | |
| 13 | +@interface CNLiveLoginTextField() | |
| 14 | +@property (nonatomic, weak) UIView *line; | |
| 15 | +@property (nonatomic, strong) UIColor *color; | |
| 16 | + | |
| 17 | +@end | |
| 18 | + | |
| 19 | +@implementation CNLiveLoginTextField | |
| 20 | +static NSString * const CNLivePlaceholderTextColor = @"_placeholderLabel.textColor"; | |
| 21 | + | |
| 22 | +- (instancetype)initWithFrame:(CGRect)frame{ | |
| 23 | + | |
| 24 | + self = [super initWithFrame:frame]; | |
| 25 | + if (self) { | |
| 26 | + [self createSubviews:frame]; | |
| 27 | + | |
| 28 | + } | |
| 29 | + return self; | |
| 30 | + | |
| 31 | +} | |
| 32 | +- (void)createSubviews:(CGRect)frame{ | |
| 33 | + UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, frame.size.height-1, frame.size.width, 0.5)]; | |
| 34 | + line.backgroundColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0]; | |
| 35 | + [self addSubview:line]; | |
| 36 | + self.line = line; | |
| 37 | +} | |
| 38 | +- (void)setLineColor:(UIColor *)lineColor{ | |
| 39 | + _lineColor = lineColor; | |
| 40 | + self.line.backgroundColor = lineColor; | |
| 41 | +} | |
| 42 | +/* | |
| 43 | +// Only override drawRect: if you perform custom drawing. | |
| 44 | +// An empty implementation adversely affects performance during animation. | |
| 45 | +- (void)drawRect:(CGRect)rect { | |
| 46 | + // Drawing code | |
| 47 | +} | |
| 48 | +*/ | |
| 49 | + | |
| 50 | ++ (void)initialize { | |
| 51 | + if (@available(iOS 13.0, *)) { | |
| 52 | + | |
| 53 | + }else{ | |
| 54 | + [self getIvars]; | |
| 55 | + } | |
| 56 | +} | |
| 57 | + | |
| 58 | +// 获取私有变量名称 | |
| 59 | ++ (void)getIvars { | |
| 60 | + unsigned int count = 0; | |
| 61 | + Ivar *ivars = class_copyIvarList([UITextField class], &count); | |
| 62 | + for (int i = 0; i < count; i++) { | |
| 63 | + Ivar ivar = ivars[i]; | |
| 64 | + NSLog(@"%s----%s", ivar_getName(ivar), ivar_getTypeEncoding(ivar)); | |
| 65 | + } | |
| 66 | + | |
| 67 | +} | |
| 68 | + | |
| 69 | +- (void)awakeFromNib { | |
| 70 | + // 设置光标的颜色 | |
| 71 | + self.tintColor = self.textColor; | |
| 72 | + [super awakeFromNib]; | |
| 73 | +} | |
| 74 | + | |
| 75 | +// 获取到焦点 | |
| 76 | +- (BOOL)becomeFirstResponder { | |
| 77 | + if (@available(iOS 13.0, *)) { | |
| 78 | + | |
| 79 | + }else{ | |
| 80 | + // 利用运行时获取key,设置占位文字的颜色 | |
| 81 | + [self setValue:self.textColor forKeyPath:CNLivePlaceholderTextColor]; | |
| 82 | + | |
| 83 | + } | |
| 84 | + return [super becomeFirstResponder]; | |
| 85 | +} | |
| 86 | + | |
| 87 | +// 失去焦点 | |
| 88 | +- (BOOL)resignFirstResponder { | |
| 89 | + if (@available(iOS 13.0, *)) { | |
| 90 | + }else{ | |
| 91 | + // 利用运行时获取key,设置占位文字的颜色 | |
| 92 | + [self setValue:self.color forKeyPath:CNLivePlaceholderTextColor]; | |
| 93 | + } | |
| 94 | + return [super resignFirstResponder]; | |
| 95 | + | |
| 96 | +} | |
| 97 | +- (void)setPlaceholderColor:(UIColor *)placeholderColor{ | |
| 98 | + _color = placeholderColor; | |
| 99 | + if (_color) { | |
| 100 | + _color = placeholderColor; | |
| 101 | + } else { | |
| 102 | + _color = [UIColor whiteColor]; | |
| 103 | + } | |
| 104 | + if (@available(iOS 13.0, *)) { | |
| 105 | + self.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.placeholder attributes:@{NSFontAttributeName:self.font, NSForegroundColorAttributeName:_color}]; | |
| 106 | + | |
| 107 | + }else{ | |
| 108 | + [self setValue:_color forKeyPath:CNLivePlaceholderTextColor]; | |
| 109 | + } | |
| 110 | + | |
| 111 | +} | |
| 112 | + | |
| 113 | +- (UIColor *)placeholderColor{ | |
| 114 | + return [self valueForKeyPath:CNLivePlaceholderTextColor]; | |
| 115 | + | |
| 116 | +} | |
| 117 | + | |
| 118 | +@end | ... | ... |
CNLiveLoginModule/Classes/View/CNLiveLoginView.h
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveLoginView.h | |
| 3 | +// CNLiveLoginModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright (c) 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <UIKit/UIKit.h> | |
| 10 | + | |
| 11 | +NS_ASSUME_NONNULL_BEGIN | |
| 12 | +@class CNLiveLoginView; | |
| 13 | +@protocol CNLiveLoginViewDelegate <NSObject> | |
| 14 | +- (void)loginSuccess:(CNLiveLoginView *)view isNewUser:(BOOL)isNewUser result:(id _Nonnull)result; | |
| 15 | + | |
| 16 | +@end | |
| 17 | +@interface CNLiveLoginView : UIView | |
| 18 | +@property (nonatomic, weak) id<CNLiveLoginViewDelegate> delegate; | |
| 19 | + | |
| 20 | +@end | |
| 21 | + | |
| 22 | +NS_ASSUME_NONNULL_END | ... | ... |
CNLiveLoginModule/Classes/View/CNLiveLoginView.m
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveLoginView.m | |
| 3 | +// CNLiveLoginModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright (c) 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "CNLiveLoginView.h" | |
| 10 | + | |
| 11 | +#import "YYKit.h" | |
| 12 | + | |
| 13 | +#import "CNLiveLoginCountryView.h" | |
| 14 | +#import "CNLiveLoginTextField.h" | |
| 15 | + | |
| 16 | +#import "CNLiveCountDownButton.h" | |
| 17 | +//#import "XWLoginNotification.h" | |
| 18 | + | |
| 19 | +@interface CNLiveLoginView()<UITextFieldDelegate, CNLiveLoginCountryViewDelegate,CNLiveCountDownButtonDataSource, CNLiveCountDownButtonDelegate> | |
| 20 | +{ | |
| 21 | + NSString *_countryCode; // 国家Code | |
| 22 | + NSString *_verificationCode; // 验证码 | |
| 23 | +} | |
| 24 | +@property (nonatomic, weak) UIImageView *logo; | |
| 25 | +@property (nonatomic, weak) CNLiveLoginCountryView *country; | |
| 26 | +@property (nonatomic, weak) CNLiveLoginTextField *account; | |
| 27 | +@property (nonatomic, weak) CNLiveLoginTextField *code; | |
| 28 | + | |
| 29 | +@property (nonatomic, strong) CNLiveCountDownButton *countDown; | |
| 30 | + | |
| 31 | +@property (nonatomic, weak) UIButton *login; | |
| 32 | + | |
| 33 | +@end | |
| 34 | + | |
| 35 | +@implementation CNLiveLoginView | |
| 36 | +static NSInteger const rowHeight = 40; | |
| 37 | +static NSInteger const space = 20; | |
| 38 | + | |
| 39 | +- (instancetype)initWithFrame:(CGRect)frame{ | |
| 40 | + | |
| 41 | + self = [super initWithFrame:frame]; | |
| 42 | + if (self) { | |
| 43 | + self.userInteractionEnabled = YES; | |
| 44 | + _countryCode = @"86"; | |
| 45 | + [self createSubviews:frame]; | |
| 46 | + | |
| 47 | + } | |
| 48 | + return self; | |
| 49 | + | |
| 50 | +} | |
| 51 | +- (void)createSubviews:(CGRect)frame{ | |
| 52 | + UIImageView *logo = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width-80)/2.0, 0, 80, 105)]; | |
| 53 | + UIImage *image1 = [self xw_getImageName:@"login_logo" bundleName:@"CNLiveLoginModule" targetClass:[self class]]; | |
| 54 | + logo.image = image1; | |
| 55 | + [self addSubview:logo]; | |
| 56 | + self.logo = logo; | |
| 57 | + | |
| 58 | + CNLiveLoginCountryView *country = [[CNLiveLoginCountryView alloc] initWithFrame:CGRectMake(0, logo.bottom+space, frame.size.width, rowHeight)]; | |
| 59 | + country.delegate = self; | |
| 60 | + [self addSubview:country]; | |
| 61 | + self.country = country; | |
| 62 | + | |
| 63 | + CNLiveLoginTextField *account = [[CNLiveLoginTextField alloc] initWithFrame:CGRectMake(country.left, country.bottom+space, frame.size.width, rowHeight)]; | |
| 64 | + account.keyboardType = UIKeyboardTypeNumberPad; | |
| 65 | + account.placeholder = @"请输入手机号"; | |
| 66 | + account.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]; | |
| 67 | + account.placeholderColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0]; | |
| 68 | + account.font = [UIFont systemFontOfSize:14]; | |
| 69 | + account.textAlignment = NSTextAlignmentLeft; | |
| 70 | + [account addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; | |
| 71 | + account.clearButtonMode = UITextFieldViewModeWhileEditing; | |
| 72 | + account.delegate = self; | |
| 73 | + [self addSubview:account]; | |
| 74 | + self.account = account; | |
| 75 | + | |
| 76 | + CNLiveLoginTextField *code = [[CNLiveLoginTextField alloc] initWithFrame:CGRectMake(country.left, account.bottom+space, frame.size.width/2.0, rowHeight)]; | |
| 77 | + code.keyboardType = UIKeyboardTypeNumberPad; | |
| 78 | + code.placeholder = @"请输入验证码"; | |
| 79 | + code.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]; | |
| 80 | + code.placeholderColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0]; | |
| 81 | + code.font = [UIFont systemFontOfSize:14]; | |
| 82 | + code.textAlignment = NSTextAlignmentLeft; | |
| 83 | + [code addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; | |
| 84 | + code.clearButtonMode = UITextFieldViewModeWhileEditing; | |
| 85 | + code.delegate = self; | |
| 86 | + [self addSubview:code]; | |
| 87 | + self.code = code; | |
| 88 | + | |
| 89 | + CNLiveCountDownButton *countDown = [CNLiveCountDownButton buttonWithType:UIButtonTypeCustom]; | |
| 90 | + countDown.dataSource = self; | |
| 91 | + countDown.delegate = self; | |
| 92 | + countDown.frame = CGRectMake(frame.size.width-80, account.bottom+space+10, 80, rowHeight-10); | |
| 93 | + UIImage *image2 = [self xw_getImageName:@"login_get_code" bundleName:@"CNLiveLoginModule" targetClass:[self class]]; | |
| 94 | + [countDown setImage:image2 forState:UIControlStateNormal]; | |
| 95 | + countDown.adjustsImageWhenHighlighted = NO; | |
| 96 | + [countDown setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; | |
| 97 | + countDown.titleLabel.font = [UIFont systemFontOfSize:12.0]; | |
| 98 | + countDown.layer.cornerRadius = 15; | |
| 99 | + countDown.layer.masksToBounds = YES; | |
| 100 | + [self addSubview:countDown]; | |
| 101 | + self.countDown = countDown; | |
| 102 | + | |
| 103 | + UIButton *login = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 104 | + login.frame = CGRectMake(5, code.bottom+space, frame.size.width-10, rowHeight); | |
| 105 | + [login setTitle:@"登录" forState:UIControlStateNormal]; | |
| 106 | + [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; | |
| 107 | + login.titleLabel.font = [UIFont systemFontOfSize:15.0]; | |
| 108 | + login.backgroundColor = [UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0]; | |
| 109 | + login.layer.cornerRadius = 20; | |
| 110 | + login.layer.masksToBounds = YES; | |
| 111 | + login.adjustsImageWhenHighlighted = NO; | |
| 112 | + [login addTarget:self action:@selector(loginDidClicked:) forControlEvents:UIControlEventTouchUpInside]; | |
| 113 | + [self addSubview:login]; | |
| 114 | + self.login = login; | |
| 115 | + | |
| 116 | +} | |
| 117 | + | |
| 118 | +#pragma mark - UITextFieldDelegate | |
| 119 | +- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ | |
| 120 | + if ([textField isEqual:_account] || [textField isEqual:_code]) { | |
| 121 | + return YES; | |
| 122 | + | |
| 123 | + } | |
| 124 | + else { | |
| 125 | + return YES; | |
| 126 | + | |
| 127 | + } | |
| 128 | +} | |
| 129 | + | |
| 130 | +- (void)textFieldDidChange:(UITextField *)textField { | |
| 131 | + if (![_account.text isEqualToString:@""] && ![_code.text isEqualToString:@""]) { | |
| 132 | + _login.enabled = YES; | |
| 133 | + | |
| 134 | + } | |
| 135 | + else { | |
| 136 | + _login.enabled = NO; | |
| 137 | + | |
| 138 | + } | |
| 139 | + | |
| 140 | +} | |
| 141 | + | |
| 142 | +- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { | |
| 143 | + if ([textField isEqual:_account]) { | |
| 144 | + NSInteger maxTextLength = 20; | |
| 145 | + if(string.length == 0) { | |
| 146 | + //判断是不是删除键 | |
| 147 | + return YES; | |
| 148 | + } | |
| 149 | + else if(textField.text.length >= maxTextLength) { | |
| 150 | + NSLog(@"输入的字符个数大于20,忽略输入"); | |
| 151 | + return NO; | |
| 152 | + } | |
| 153 | + else if (![self isNum:string]) { | |
| 154 | + return NO; | |
| 155 | + } | |
| 156 | + else if (textField.text.length + string.length > maxTextLength){ | |
| 157 | + NSInteger length = textField.text.length; | |
| 158 | + NSInteger needLen = maxTextLength - length; | |
| 159 | + textField.text = [textField.text stringByAppendingString:[string substringToIndex:needLen]]; | |
| 160 | + return NO; | |
| 161 | + } | |
| 162 | + else{ | |
| 163 | + return YES; | |
| 164 | + } | |
| 165 | + } | |
| 166 | + else if ([textField isEqual:self.code]){ | |
| 167 | + NSInteger maxTextLength = 6; | |
| 168 | + if(string.length == 0) { | |
| 169 | + //判断是不是删除键 | |
| 170 | + return YES; | |
| 171 | + } | |
| 172 | + else if(textField.text.length >= maxTextLength) { | |
| 173 | + NSLog(@"输入的字符个数大于6,忽略输入"); | |
| 174 | + return NO; | |
| 175 | + } | |
| 176 | + else if (![self isNum:string]) { | |
| 177 | + return NO; | |
| 178 | + } | |
| 179 | + else if (textField.text.length + string.length > maxTextLength){ | |
| 180 | + NSInteger length = textField.text.length; | |
| 181 | + NSInteger needLen = maxTextLength - length; | |
| 182 | + textField.text = [textField.text stringByAppendingString:[string substringToIndex:needLen]]; | |
| 183 | + return NO; | |
| 184 | + } | |
| 185 | + else{ | |
| 186 | + return YES; | |
| 187 | + } | |
| 188 | + } | |
| 189 | + else{ | |
| 190 | + return YES; | |
| 191 | + } | |
| 192 | +} | |
| 193 | + | |
| 194 | +/** 判断是否为纯数字 */ | |
| 195 | +- (BOOL)isNum:(NSString *)checkedNumString { | |
| 196 | + checkedNumString = [checkedNumString stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]]; | |
| 197 | + if(checkedNumString.length > 0) { | |
| 198 | + return NO; | |
| 199 | + } | |
| 200 | + return YES; | |
| 201 | +} | |
| 202 | + | |
| 203 | +/* | |
| 204 | +// Only override drawRect: if you perform custom drawing. | |
| 205 | +// An empty implementation adversely affects performance during animation. | |
| 206 | +- (void)drawRect:(CGRect)rect { | |
| 207 | + // Drawing code | |
| 208 | +} | |
| 209 | +*/ | |
| 210 | + | |
| 211 | +#pragma mark - XWLoginCountryViewDelegate | |
| 212 | +- (void)selectCountryName:(NSString *)countryName countryCode:(NSString *)countryCode{ | |
| 213 | + [_account resignFirstResponder]; | |
| 214 | + [_code resignFirstResponder]; | |
| 215 | + | |
| 216 | + if(![_countryCode isEqualToString:countryCode]){ | |
| 217 | + _countryCode = countryCode; | |
| 218 | + | |
| 219 | + } | |
| 220 | + | |
| 221 | +} | |
| 222 | +#pragma mark - XWCountDownButton DataSource | |
| 223 | +// 设置倒计时总秒数 | |
| 224 | +- (NSInteger)startCountDownNumOfCountDownButton:(CNLiveCountDownButton *)countdownButton { | |
| 225 | + return 60; | |
| 226 | +} | |
| 227 | + | |
| 228 | +#pragma mark - XWCountdownButton Delegate | |
| 229 | +// 倒计时按钮点击 | |
| 230 | +- (void)countDownButtonDidClick:(CNLiveCountDownButton *)button { | |
| 231 | + //获取验证码 | |
| 232 | + __weak typeof(self) weakSelf = self; | |
| 233 | + if ([_account.text isEqualToString:@""]) { | |
| 234 | +// [XWAlertView alertViewWithFlexTextMessage:@"请输入手机号" view:nil]; | |
| 235 | + return; | |
| 236 | + } | |
| 237 | + // 按钮点击后将enabled设置为NO | |
| 238 | + button.userInteractionEnabled = NO; | |
| 239 | + | |
| 240 | +// [XWUserRequest verificationCodeWithType:XWCodeTypeShortcutLogin mobile:_account.text countryCode:_countryCode success:^(id _Nonnull result) { | |
| 241 | +// __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 242 | +// if(!strongSelf) return; | |
| 243 | +// // 获取的验证码 | |
| 244 | +// strongSelf->_verificationCode = @"666666"; | |
| 245 | +// | |
| 246 | +// [XWAlertView alertSucceedViewWithTextMessage:@"获取成功" view:nil]; | |
| 247 | +// button.backgroundColor = HexColor(0xdedede); | |
| 248 | +// button.frame = CGRectMake(self.frame.size.width-110, self.account.bottom+space+10, 110, rowHeight-10); | |
| 249 | +// [button setImage:nil forState:UIControlStateNormal]; | |
| 250 | +// NSString *title = [NSString stringWithFormat:@"%d秒后重新发送", 60]; | |
| 251 | +// [button setTitle:title forState:UIControlStateNormal]; | |
| 252 | +// [button startCountDown]; | |
| 253 | +// | |
| 254 | +// } failure:^(NSDictionary * _Nonnull errorDic) { | |
| 255 | +// __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 256 | +// if(!strongSelf) return; | |
| 257 | +// button.userInteractionEnabled = YES; | |
| 258 | +// [XWAlertView alertErrorViewWithTextMessage:@"获取失败" view:nil]; | |
| 259 | +// | |
| 260 | +// }]; | |
| 261 | + | |
| 262 | + | |
| 263 | +} | |
| 264 | + | |
| 265 | +// 倒计时进行中 | |
| 266 | +- (void)countDownButtonDidCountDown:(CNLiveCountDownButton *)button countDownNum:(NSInteger)countDownNum { | |
| 267 | + if(button.frame.size.width != 110){ | |
| 268 | + button.frame = CGRectMake(self.frame.size.width-110, self.account.bottom+space+10, 110, rowHeight-10); | |
| 269 | + } | |
| 270 | + NSString *title = [NSString stringWithFormat:@"%ld秒后重新发送", countDownNum]; | |
| 271 | + [button setTitle:title forState:UIControlStateNormal]; | |
| 272 | + | |
| 273 | +} | |
| 274 | + | |
| 275 | +// 倒计时结束 | |
| 276 | +- (void)countDownButtonDidEndCountDown:(CNLiveCountDownButton *)button { | |
| 277 | + button.frame = CGRectMake(self.frame.size.width-80, self.account.bottom+space+10, 80, rowHeight-10); | |
| 278 | + button.backgroundColor = [UIColor whiteColor]; | |
| 279 | + button.userInteractionEnabled = YES; | |
| 280 | + [button setTitle:@"" forState:UIControlStateNormal]; | |
| 281 | + UIImage *image2 = [self xw_getImageName:@"login_get_code" bundleName:@"CNLiveLoginModule" targetClass:[self class]]; | |
| 282 | + [button setImage:image2 forState:UIControlStateNormal]; | |
| 283 | +} | |
| 284 | + | |
| 285 | +#pragma mark - Action | |
| 286 | +- (void)loginDidClicked:(UIButton *)btn{ | |
| 287 | + //登录 | |
| 288 | + _verificationCode = @"666666"; | |
| 289 | + if ([_account.text isEqualToString:@""]) { | |
| 290 | +// [XWAlertView alertViewWithFlexTextMessage:@"请输入手机号" view:self.superview]; | |
| 291 | + return; | |
| 292 | + } | |
| 293 | + if ([_code.text isEqualToString:@""]) { | |
| 294 | +// [XWAlertView alertViewWithFlexTextMessage:@"请输入验证码" view:self.superview]; | |
| 295 | + return; | |
| 296 | + } | |
| 297 | + btn.userInteractionEnabled = NO; | |
| 298 | + // 隐藏键盘 | |
| 299 | + [self.superview endEditing:YES]; | |
| 300 | + __weak typeof(self) weakSelf = self; | |
| 301 | +// [XWUserRequest shortcutLoginWithUserName:_account.text verificationCode:_verificationCode countryCode:_countryCode fromId:@"apple" success:^(id _Nonnull result) { | |
| 302 | +// btn.userInteractionEnabled = YES; | |
| 303 | +// __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 304 | +// if(!strongSelf) return; | |
| 305 | +// [XWUserManager defaultConfiguration:result]; | |
| 306 | +// // YES 新用户 NO 老用户 | |
| 307 | +// BOOL isNewUser = YES; | |
| 308 | +// if (strongSelf.delegate && [strongSelf.delegate respondsToSelector:@selector(loginSuccess:isNewUser:result:)]) { | |
| 309 | +// [strongSelf.delegate loginSuccess:strongSelf isNewUser:isNewUser result:result]; | |
| 310 | +// } | |
| 311 | +// | |
| 312 | +// } failure:^(NSDictionary * _Nonnull errorDic) { | |
| 313 | +// btn.userInteractionEnabled = YES; | |
| 314 | +// __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 315 | +// if(!strongSelf) return; | |
| 316 | +//// [XWAlterView alertErrorViewWithTextMessage:@"登录失败" view:strongSelf.superview]; | |
| 317 | +// | |
| 318 | +// // ------ 最后删除 ------ | |
| 319 | +// NSDictionary *dic = @{@"token":@"用户token",@"id":@"用户id",@"tel":@"17600922519",@"faceUrl":@"http://pic1.win4000.com/wallpaper/c/53cdd1f7c1f21.jpg",@"name":@"张璟熙",@"gender":@"0",@"address":@"北京市海淀区"}; | |
| 320 | +// [XWUserManager defaultConfiguration:dic]; | |
| 321 | +// BOOL isNewUser = YES; | |
| 322 | +// if (strongSelf.delegate && [strongSelf.delegate respondsToSelector:@selector(loginSuccess:isNewUser:result:)]) { | |
| 323 | +// [strongSelf.delegate loginSuccess:strongSelf isNewUser:isNewUser result:errorDic]; | |
| 324 | +// } | |
| 325 | +// // ------ 最后删除 ------ | |
| 326 | +// | |
| 327 | +// }]; | |
| 328 | + | |
| 329 | +} | |
| 330 | + | |
| 331 | +/** | |
| 332 | + * 创建图片 | |
| 333 | + * | |
| 334 | + * @param imageName 图片名字 | |
| 335 | + * @param bundleName 图片所在的bundle名字 | |
| 336 | + * @param targetClass 类和bundle的同级目录 | |
| 337 | + * @return 返回UIImage | |
| 338 | + */ | |
| 339 | +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{ | |
| 340 | + NSBundle *bundle = [NSBundle bundleForClass:targetClass]; | |
| 341 | + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"]; | |
| 342 | + NSBundle *targetBundle = [NSBundle bundleWithURL:url]; | |
| 343 | + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil]; | |
| 344 | + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil]; | |
| 345 | +} | |
| 346 | + | |
| 347 | +@end | ... | ... |