// // QXThirdLoginView.m // QXLive // // Created by 启星 on 2025/5/7. // #import "QXLoginBottomView.h" #import "NSAttributedString+YYText.h" @interface QXLoginBottomView() @property (nonatomic,strong)UILabel *titleLabel; @property (nonatomic,strong)QXLoginAgreementView *agreeView; @end @implementation QXLoginBottomView -(instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; } return self; } -(void)initSubViews{ self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.width, 20)]; self.titleLabel.text = QXText(@"其他方式登录"); self.titleLabel.textColor = RGB16(0x666666); self.titleLabel.textAlignment = NSTextAlignmentCenter; self.titleLabel.font = [UIFont systemFontOfSize:12]; [self addSubview:self.titleLabel]; } -(void)setIsDefaultAgree:(BOOL)isDefaultAgree{ _isDefaultAgree = isDefaultAgree; self.agreeView.agreeBtn.selected = isDefaultAgree; } -(void)setThirdArray:(NSArray *)thirdArray{ _thirdArray = thirdArray; CGFloat startX = 0; CGFloat btnWidth = 30; CGFloat btnMargin = 16; if (thirdArray.count == 0) { self.titleLabel.hidden = YES; return; } self.titleLabel.hidden = NO; if (thirdArray.count == 1) { startX = SCREEN_WIDTH/2.0-btnWidth/2.0; }else if (thirdArray.count == 2){ startX = SCREEN_WIDTH/2.0-btnMargin/2.0-btnWidth; }else if (thirdArray.count == 3){ startX = SCREEN_WIDTH/2.0-btnWidth/2.0-btnMargin-btnWidth; }else if (thirdArray.count == 3){ startX = SCREEN_WIDTH/2.0-btnMargin/2.0-btnMargin-2*btnWidth; } for (int i = 0 ; i < thirdArray.count;i++) { NSDictionary *dict = thirdArray[i]; NSInteger type = [dict[@"type"] integerValue]; NSString *icon = [NSString stringWithFormat:@"%@",dict[@"icon"]]; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(startX+(btnMargin+btnWidth)*i, self.titleLabel.bottom+14, btnWidth, btnWidth)]; [btn setImage:[UIImage imageNamed:icon] forState:(UIControlStateNormal)]; btn.tag = type; [btn addTarget:self action:@selector(thirdLoginAction:) forControlEvents:(UIControlEventTouchUpInside)]; [self addSubview:btn]; } self.agreeView = [[QXLoginAgreementView alloc] initWithFrame:CGRectMake(0, self.titleLabel.bottom+103, SCREEN_WIDTH, 30)]; self.agreeView.delegate = self; [self addSubview:self.agreeView]; } -(void)thirdLoginAction:(UIButton*)sender{ if (self.delegate && [self.delegate respondsToSelector:@selector(thirdLoginWithType:)]) { [self.delegate thirdLoginWithType:sender.tag]; } } -(void)didClickAgree:(BOOL)isAgree{ if (self.delegate && [self.delegate respondsToSelector:@selector(didClickAgree:)]) { [self.delegate didClickAgree:isAgree]; } } -(void)didClickAgreementLoginWithUrl:(NSString *)url type:(NSInteger)type{ if (self.delegate && [self.delegate respondsToSelector:@selector(didClickAgreementLoginWithUrl:type:)]) { [self.delegate didClickAgreementLoginWithUrl:url type:type]; } } @end @implementation QXLoginAgreementView -(instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; } return self; } -(void)initSubViews{ self.agreeBtn = [[UIButton alloc] initWithFrame:CGRectMake(40, 0, 30, 30)]; [self.agreeBtn setImage:[UIImage imageNamed:@"login_agreement_nor"] forState:(UIControlStateNormal)]; [self.agreeBtn setImage:[UIImage imageNamed:@"login_agreement_sel"] forState:(UIControlStateSelected)]; [self addSubview:self.agreeBtn]; [self.agreeBtn addTarget:self action:@selector(agreeAction:) forControlEvents:(UIControlEventTouchUpInside)]; NSString *str = [NSString stringWithFormat:@"%@%@%@%@",QXText(@"我已阅读并同意"),QXText(@"《用户使用协议》"),QXText(@"和"),QXText(@"《隐私政策》")]; NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:str]; MJWeakSelf [attr yy_setTextHighlightRange:[str rangeOfString:QXText(@"《用户使用协议》")] color:QXConfig.themeColor backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(didClickAgreementLoginWithUrl:type:)]) { [weakSelf.delegate didClickAgreementLoginWithUrl:@"111" type:1]; } }]; [attr yy_setTextHighlightRange:[str rangeOfString:QXText(@"《隐私政策》")] color:QXConfig.themeColor backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(didClickAgreementLoginWithUrl:type:)]) { [weakSelf.delegate didClickAgreementLoginWithUrl:@"111" type:2]; } }]; [attr yy_setFont:[UIFont systemFontOfSize:12] range:NSMakeRange(0, str.length)]; [attr yy_setColor:RGB16(0x333333) range:NSMakeRange(0, str.length)]; [attr yy_setColor:QXConfig.themeColor range:[str rangeOfString:QXText(@"《用户使用协议》")]]; [attr yy_setColor:QXConfig.themeColor range:[str rangeOfString:QXText(@"《隐私政策》")]]; _textLabel = [[YYLabel alloc] initWithFrame:CGRectMake(self.agreeBtn.right, 0, self.width-80-25, self.height)]; _textLabel.attributedText = attr; _textLabel.userInteractionEnabled = YES; [self addSubview:_textLabel]; } -(void)agreeAction:(UIButton*)sender{ self.agreeBtn.selected = !self.agreeBtn.selected; if (self.delegate && [self.delegate respondsToSelector:@selector(didClickAgree:)]) { [self.delegate didClickAgree:self.agreeBtn.selected]; } } @end