// // YMLoginRegistrAgreementPopupView.m // MSYOUPAI // // Created by YoMi on 2024/2/10. // Copyright © 2024 MS. All rights reserved. // #import "YMLoginRegistrAgreementPopupView.h" static NSString *const warmTipsTitle = @"用户协议与隐私政策"; static NSString *const warmTipsContent = @"注册登录前需您阅读并同意《用户协议》与《隐私政策》"; @interface YMLoginRegistrAgreementPopupView () /** 标题标签*/ @property (nonatomic, strong) UILabel *titleLb; /** 提示文本*/ @property (nonatomic, strong) YYLabel *tipsLb; /** 按钮视图*/ @property (nonatomic, strong) UIView *buttonView; /** 取消按钮*/ @property (nonatomic, strong) UIButton *cancelBtn; /** 确认按钮*/ @property (nonatomic, strong) UIButton *confirmBtn; @end @implementation YMLoginRegistrAgreementPopupView - (void)ym_setupViews{ self.backgroundColor = HexColorFromRGB(0xFFFFFF); [self addSubview:self.titleLb]; [self addSubview:self.tipsLb]; [self addSubview:self.buttonView]; [self.buttonView addSubview:self.cancelBtn]; [self.buttonView addSubview:self.confirmBtn]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; [self configurationWithTitleStr:warmTipsTitle ContentStr:warmTipsContent]; } - (void)updateConstraints{ [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).offset(adapt(20)); make.left.equalTo(self).offset(adapt(20)); make.right.equalTo(self).offset(adapt(-20)); make.height.mas_equalTo(adapt(25)); }]; [self.tipsLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.titleLb.mas_bottom).offset(adapt(10)); make.left.equalTo(self).offset(adapt(20)); make.right.equalTo(self).offset(adapt(-20)); }]; [self.buttonView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.tipsLb.mas_bottom).offset(adapt(10)); make.left.equalTo(self); make.right.equalTo(self); make.bottom.equalTo(self).offset(adapt(-10)).priorityHigh(); make.height.mas_equalTo(adapt(100)); }]; NSArray *btnArr = @[self.confirmBtn,self.cancelBtn]; // 实现masonry水平固定控件宽度方法 // axisType 横排还是竖排 // fixedSpacing 两个控件间隔 // leadSpacing 第一个控件与边缘的间隔 // tailSpacing 最后一个控件与边缘的间隔 [btnArr mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:adapt(10) leadSpacing:adapt(5) tailSpacing:adapt(5)]; // 设置array的垂直方向的约束 [btnArr mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.mas_centerX); make.width.mas_equalTo(adapt(200)); }]; [super updateConstraints]; } - (void)configurationWithTitleStr:(NSString*)titleStr ContentStr:(NSString *)contentStr{ NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr]; attributedString.yy_font = LCFont(14); attributedString.yy_color = HexColorFromRGB(0x333333); attributedString.yy_lineSpacing = 5; attributedString.yy_alignment = NSTextAlignmentLeft; NSString *userAgreementHighlightStr = @"《用户协议》"; NSArray *userAgreementArray = [self rangeOfSubString:userAgreementHighlightStr inString:contentStr]; for (NSInteger i = 0; i < userAgreementArray.count; i++) { NSValue *value = userAgreementArray[i]; //添加下划线 // YYTextDecoration* deco = [YYTextDecoration decorationWithStyle:(YYTextLineStyleSingle) width:[NSNumber numberWithInt:1] color:HEXCOLOR(0xFF0000)]; // [attributedString yy_setTextUnderline:deco range:value.rangeValue]; [attributedString yy_setTextHighlightRange:value.rangeValue color:AGREEMENTColor backgroundColor:[UIColor clearColor] tapAction:^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect){ if (self.dismissBlock) { self.dismissBlock(); } YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{ ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserProtocolH5] }]; [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{ RouterViewModel:webArticleVM } completion:nil]; }]; } NSString *privacyAgreementHighlightStr = @"《隐私政策》"; NSArray *privacyAgreementArray = [self rangeOfSubString:privacyAgreementHighlightStr inString:contentStr]; for (NSInteger i = 0; i < privacyAgreementArray.count; i++) { NSValue *value = privacyAgreementArray[i]; //添加下划线 // YYTextDecoration* deco = [YYTextDecoration decorationWithStyle:(YYTextLineStyleSingle) width:[NSNumber numberWithInt:1] color:HEXCOLOR(0xFF0000)]; // [attributedString yy_setTextUnderline:deco range:value.rangeValue]; [attributedString yy_setTextHighlightRange:value.rangeValue color:AGREEMENTColor backgroundColor:[UIColor clearColor] tapAction:^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect){ if (self.dismissBlock) { self.dismissBlock(); } YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{ ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserPrivacyH5] }]; [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{ RouterViewModel:webArticleVM } completion:nil]; }]; } self.tipsLb.attributedText = attributedString; CGSize introSize = CGSizeMake(kFrameWidth*0.8 - adapt(20)*2, CGFLOAT_MAX); YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:introSize text:attributedString]; self.tipsLb.textLayout = layout; CGFloat tipsLbHeight = layout.textBoundingSize.height; [self.tipsLb mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(tipsLbHeight); }]; CGFloat titleLbHeight = [self.titleLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height; CGFloat buttonViewHeight = [self.buttonView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height; self.frame = CGRectMake(0, 0, kFrameWidth*0.8, adapt(20) + titleLbHeight + adapt(10) + tipsLbHeight + adapt(10) + buttonViewHeight + adapt(20)); } #pragma mark - 获取字符串的所在位置 //获取一个字符在字符串中出现的所有位置 返回一个被NSValue包装的NSRange数组 - (NSArray *)rangeOfSubString:(NSString *)subStr inString:(NSString *)string { if (subStr == nil && [subStr isEqualToString:@""]) { return nil; } NSMutableArray *rangeArray = [NSMutableArray array]; NSString *string1 = [string stringByAppendingString:subStr]; NSString *temp; for (int i = 0; i < string.length; i ++) { temp = [string1 substringWithRange:NSMakeRange(i, subStr.length)]; if ([temp isEqualToString:subStr]) { NSRange range = {i,subStr.length}; [rangeArray addObject:[NSValue valueWithRange:range]]; } } return rangeArray; } #pragma mark - lazyload - (UILabel *)titleLb{ if (!_titleLb) { _titleLb = [[UILabel alloc]init]; _titleLb.font = LCBoldFont(18); _titleLb.textColor = HexColorFromRGB(0x1B2739); _titleLb.textAlignment = NSTextAlignmentCenter; _titleLb.text = @"提示"; } return _titleLb; } - (YYLabel *)tipsLb{ if (!_tipsLb) { _tipsLb = [[YYLabel alloc]init]; _tipsLb.font = LCFont(14); _tipsLb.textAlignment = NSTextAlignmentLeft; } return _tipsLb; } - (UIView *)buttonView{ if (!_buttonView) { _buttonView = [[UIView alloc]init]; } return _buttonView; } - (UIButton *)confirmBtn { if(!_confirmBtn){ _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _confirmBtn.titleLabel.font = LCFont(15); [_confirmBtn setTitle:@"确定" forState:UIControlStateNormal]; [_confirmBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal]; _confirmBtn.layer.cornerRadius = adapt(40)/2; [_confirmBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP]; WS(weakSelf) [[[_confirmBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { if (weakSelf.buttonBlock) { weakSelf.buttonBlock(YES); } }]; } return _confirmBtn; } - (UIButton *)cancelBtn { if(!_cancelBtn){ _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _cancelBtn.titleLabel.font = LCFont(13); [_cancelBtn setTitle:@"不同意" forState:UIControlStateNormal]; [_cancelBtn setTitleColor:HexColorFromRGB(0x555555) forState:UIControlStateNormal]; WS(weakSelf) [[[_cancelBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { if (weakSelf.buttonBlock) { weakSelf.buttonBlock(NO); } }]; } return _cancelBtn; } @end