YMLoginRegistrAgreementPopupView.m 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. //
  2. // YMLoginRegistrAgreementPopupView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/10.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMLoginRegistrAgreementPopupView.h"
  9. static NSString *const warmTipsTitle = @"用户协议与隐私政策";
  10. static NSString *const warmTipsContent = @"注册登录前需您阅读并同意《用户协议》与《隐私政策》";
  11. @interface YMLoginRegistrAgreementPopupView ()
  12. /** 标题标签*/
  13. @property (nonatomic, strong) UILabel *titleLb;
  14. /** 提示文本*/
  15. @property (nonatomic, strong) YYLabel *tipsLb;
  16. /** 按钮视图*/
  17. @property (nonatomic, strong) UIView *buttonView;
  18. /** 取消按钮*/
  19. @property (nonatomic, strong) UIButton *cancelBtn;
  20. /** 确认按钮*/
  21. @property (nonatomic, strong) UIButton *confirmBtn;
  22. @end
  23. @implementation YMLoginRegistrAgreementPopupView
  24. - (void)ym_setupViews{
  25. self.backgroundColor = HexColorFromRGB(0xFFFFFF);
  26. [self addSubview:self.titleLb];
  27. [self addSubview:self.tipsLb];
  28. [self addSubview:self.buttonView];
  29. [self.buttonView addSubview:self.cancelBtn];
  30. [self.buttonView addSubview:self.confirmBtn];
  31. [self setNeedsUpdateConstraints];
  32. [self updateConstraintsIfNeeded];
  33. [self configurationWithTitleStr:warmTipsTitle ContentStr:warmTipsContent];
  34. }
  35. - (void)updateConstraints{
  36. [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.top.equalTo(self).offset(adapt(20));
  38. make.left.equalTo(self).offset(adapt(20));
  39. make.right.equalTo(self).offset(adapt(-20));
  40. make.height.mas_equalTo(adapt(25));
  41. }];
  42. [self.tipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.top.equalTo(self.titleLb.mas_bottom).offset(adapt(10));
  44. make.left.equalTo(self).offset(adapt(20));
  45. make.right.equalTo(self).offset(adapt(-20));
  46. }];
  47. [self.buttonView mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.top.equalTo(self.tipsLb.mas_bottom).offset(adapt(10));
  49. make.left.equalTo(self);
  50. make.right.equalTo(self);
  51. make.bottom.equalTo(self).offset(adapt(-10)).priorityHigh();
  52. make.height.mas_equalTo(adapt(100));
  53. }];
  54. NSArray *btnArr = @[self.confirmBtn,self.cancelBtn];
  55. // 实现masonry水平固定控件宽度方法
  56. // axisType 横排还是竖排
  57. // fixedSpacing 两个控件间隔
  58. // leadSpacing 第一个控件与边缘的间隔
  59. // tailSpacing 最后一个控件与边缘的间隔
  60. [btnArr mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:adapt(10) leadSpacing:adapt(5) tailSpacing:adapt(5)];
  61. // 设置array的垂直方向的约束
  62. [btnArr mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.centerX.equalTo(self.mas_centerX);
  64. make.width.mas_equalTo(adapt(200));
  65. }];
  66. [super updateConstraints];
  67. }
  68. - (void)configurationWithTitleStr:(NSString*)titleStr ContentStr:(NSString *)contentStr{
  69. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr];
  70. attributedString.yy_font = LCFont(14);
  71. attributedString.yy_color = HexColorFromRGB(0x333333);
  72. attributedString.yy_lineSpacing = 5;
  73. attributedString.yy_alignment = NSTextAlignmentLeft;
  74. NSString *userAgreementHighlightStr = @"《用户协议》";
  75. NSArray *userAgreementArray = [self rangeOfSubString:userAgreementHighlightStr inString:contentStr];
  76. for (NSInteger i = 0; i < userAgreementArray.count; i++) {
  77. NSValue *value = userAgreementArray[i];
  78. //添加下划线
  79. // YYTextDecoration* deco = [YYTextDecoration decorationWithStyle:(YYTextLineStyleSingle) width:[NSNumber numberWithInt:1] color:HEXCOLOR(0xFF0000)];
  80. // [attributedString yy_setTextUnderline:deco range:value.rangeValue];
  81. [attributedString yy_setTextHighlightRange:value.rangeValue
  82. color:AGREEMENTColor
  83. backgroundColor:[UIColor clearColor]
  84. tapAction:^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect){
  85. if (self.dismissBlock) {
  86. self.dismissBlock();
  87. }
  88. YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
  89. ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserProtocolH5]
  90. }];
  91. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
  92. RouterViewModel:webArticleVM
  93. } completion:nil];
  94. }];
  95. }
  96. NSString *privacyAgreementHighlightStr = @"《隐私政策》";
  97. NSArray *privacyAgreementArray = [self rangeOfSubString:privacyAgreementHighlightStr inString:contentStr];
  98. for (NSInteger i = 0; i < privacyAgreementArray.count; i++) {
  99. NSValue *value = privacyAgreementArray[i];
  100. //添加下划线
  101. // YYTextDecoration* deco = [YYTextDecoration decorationWithStyle:(YYTextLineStyleSingle) width:[NSNumber numberWithInt:1] color:HEXCOLOR(0xFF0000)];
  102. // [attributedString yy_setTextUnderline:deco range:value.rangeValue];
  103. [attributedString yy_setTextHighlightRange:value.rangeValue
  104. color:AGREEMENTColor
  105. backgroundColor:[UIColor clearColor]
  106. tapAction:^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect){
  107. if (self.dismissBlock) {
  108. self.dismissBlock();
  109. }
  110. YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
  111. ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserPrivacyH5]
  112. }];
  113. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
  114. RouterViewModel:webArticleVM
  115. } completion:nil];
  116. }];
  117. }
  118. self.tipsLb.attributedText = attributedString;
  119. CGSize introSize = CGSizeMake(kFrameWidth*0.8 - adapt(20)*2, CGFLOAT_MAX);
  120. YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:introSize text:attributedString];
  121. self.tipsLb.textLayout = layout;
  122. CGFloat tipsLbHeight = layout.textBoundingSize.height;
  123. [self.tipsLb mas_updateConstraints:^(MASConstraintMaker *make) {
  124. make.height.mas_equalTo(tipsLbHeight);
  125. }];
  126. CGFloat titleLbHeight = [self.titleLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  127. CGFloat buttonViewHeight = [self.buttonView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  128. self.frame = CGRectMake(0, 0, kFrameWidth*0.8, adapt(20) + titleLbHeight + adapt(10) + tipsLbHeight + adapt(10) + buttonViewHeight + adapt(20));
  129. }
  130. #pragma mark - 获取字符串的所在位置
  131. //获取一个字符在字符串中出现的所有位置 返回一个被NSValue包装的NSRange数组
  132. - (NSArray *)rangeOfSubString:(NSString *)subStr inString:(NSString *)string {
  133. if (subStr == nil && [subStr isEqualToString:@""]) {
  134. return nil;
  135. }
  136. NSMutableArray *rangeArray = [NSMutableArray array];
  137. NSString *string1 = [string stringByAppendingString:subStr];
  138. NSString *temp;
  139. for (int i = 0; i < string.length; i ++) {
  140. temp = [string1 substringWithRange:NSMakeRange(i, subStr.length)];
  141. if ([temp isEqualToString:subStr]) {
  142. NSRange range = {i,subStr.length};
  143. [rangeArray addObject:[NSValue valueWithRange:range]];
  144. }
  145. }
  146. return rangeArray;
  147. }
  148. #pragma mark - lazyload
  149. - (UILabel *)titleLb{
  150. if (!_titleLb) {
  151. _titleLb = [[UILabel alloc]init];
  152. _titleLb.font = LCBoldFont(18);
  153. _titleLb.textColor = HexColorFromRGB(0x1B2739);
  154. _titleLb.textAlignment = NSTextAlignmentCenter;
  155. _titleLb.text = @"提示";
  156. }
  157. return _titleLb;
  158. }
  159. - (YYLabel *)tipsLb{
  160. if (!_tipsLb) {
  161. _tipsLb = [[YYLabel alloc]init];
  162. _tipsLb.font = LCFont(14);
  163. _tipsLb.textAlignment = NSTextAlignmentLeft;
  164. }
  165. return _tipsLb;
  166. }
  167. - (UIView *)buttonView{
  168. if (!_buttonView) {
  169. _buttonView = [[UIView alloc]init];
  170. }
  171. return _buttonView;
  172. }
  173. - (UIButton *)confirmBtn {
  174. if(!_confirmBtn){
  175. _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  176. _confirmBtn.titleLabel.font = LCFont(15);
  177. [_confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
  178. [_confirmBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal];
  179. _confirmBtn.layer.cornerRadius = adapt(40)/2;
  180. [_confirmBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  181. WS(weakSelf)
  182. [[[_confirmBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  183. if (weakSelf.buttonBlock) {
  184. weakSelf.buttonBlock(YES);
  185. }
  186. }];
  187. }
  188. return _confirmBtn;
  189. }
  190. - (UIButton *)cancelBtn {
  191. if(!_cancelBtn){
  192. _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  193. _cancelBtn.titleLabel.font = LCFont(13);
  194. [_cancelBtn setTitle:@"不同意" forState:UIControlStateNormal];
  195. [_cancelBtn setTitleColor:HexColorFromRGB(0x555555) forState:UIControlStateNormal];
  196. WS(weakSelf)
  197. [[[_cancelBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  198. if (weakSelf.buttonBlock) {
  199. weakSelf.buttonBlock(NO);
  200. }
  201. }];
  202. }
  203. return _cancelBtn;
  204. }
  205. @end