YMVersionUpdatePopupView.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. //
  2. // YMVersionUpdatePopupView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/21.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMVersionUpdatePopupView.h"
  9. @interface YMVersionUpdatePopupView ()
  10. /** 基础视图*/
  11. @property (nonatomic, strong) UIView *baseView;
  12. /** 版本更新封面图*/
  13. @property (nonatomic, strong) UIImageView *versionUpdateCoverView;
  14. /** 标题标签*/
  15. @property (nonatomic, strong) UILabel *titleLb;
  16. /** 提示文本*/
  17. @property (nonatomic, strong) YYLabel *tipsLb;
  18. /** 按钮视图*/
  19. @property (nonatomic, strong) UIView *buttonView;
  20. /** 取消按钮*/
  21. @property (nonatomic, strong) UIButton *cancelBtn;
  22. /** 确认按钮*/
  23. @property (nonatomic, strong) UIButton *confirmBtn;
  24. /** 单确认按钮*/
  25. @property (nonatomic, strong) UIButton *singleConfirmBtn;
  26. @end
  27. @implementation YMVersionUpdatePopupView
  28. - (void)ym_setupViews{
  29. [self addSubview:self.baseView];
  30. [self addSubview:self.versionUpdateCoverView];
  31. [self.baseView addSubview:self.titleLb];
  32. [self.baseView addSubview:self.tipsLb];
  33. [self.baseView addSubview:self.buttonView];
  34. [self.buttonView addSubview:self.cancelBtn];
  35. [self.buttonView addSubview:self.confirmBtn];
  36. [self setNeedsUpdateConstraints];
  37. [self updateConstraintsIfNeeded];
  38. }
  39. - (void)updateConstraints{
  40. [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.top.equalTo(self.versionUpdateCoverView).offset(adapt(35));
  42. make.left.equalTo(self);
  43. make.right.equalTo(self);
  44. make.bottom.equalTo(self);
  45. }];
  46. [self.versionUpdateCoverView mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.top.equalTo(self);
  48. make.left.equalTo(self.baseView);
  49. make.right.equalTo(self.baseView);
  50. make.height.mas_equalTo(adapt(200));
  51. }];
  52. [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.top.equalTo(self.versionUpdateCoverView.mas_bottom).offset(adapt(15));
  54. make.left.equalTo(self.baseView).offset(adapt(30));
  55. make.right.equalTo(self.baseView).offset(adapt(-30));
  56. }];
  57. [self.tipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.top.equalTo(self.titleLb.mas_bottom).offset(adapt(15));
  59. make.left.equalTo(self).offset(adapt(30));
  60. make.right.equalTo(self).offset(adapt(-30));
  61. }];
  62. [self.buttonView mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.top.equalTo(self.tipsLb.mas_bottom).offset(adapt(15));
  64. make.left.equalTo(self);
  65. make.right.equalTo(self);
  66. make.bottom.equalTo(self).offset(adapt(-15));
  67. make.height.mas_equalTo(adapt(110));
  68. }];
  69. NSArray *btnArr = @[self.confirmBtn,self.cancelBtn];
  70. // 实现masonry水平固定控件宽度方法
  71. // axisType 横排还是竖排
  72. // fixedSpacing 两个控件间隔
  73. // leadSpacing 第一个控件与边缘的间隔
  74. // tailSpacing 最后一个控件与边缘的间隔
  75. [btnArr mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:adapt(10) leadSpacing:adapt(10) tailSpacing:adapt(10)];
  76. // 设置array的垂直方向的约束
  77. [btnArr mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.left.equalTo(self.buttonView).offset(adapt(50));
  79. make.right.equalTo(self.buttonView).offset(adapt(-50));
  80. }];
  81. [super updateConstraints];
  82. }
  83. - (void)configutationWithTips:(NSString *)tipsStr{
  84. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:tipsStr];
  85. attributedString.yy_font = LCFont(15);
  86. attributedString.yy_color = HexColorFromRGB(0x333333);
  87. attributedString.yy_lineSpacing = adapt(5);
  88. attributedString.yy_alignment = NSTextAlignmentLeft;
  89. self.tipsLb.attributedText = attributedString;
  90. CGSize introSize = CGSizeMake(kFrameWidth*0.8 - adapt(30)*2, CGFLOAT_MAX);
  91. YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:introSize text:attributedString];
  92. self.tipsLb.textLayout = layout;
  93. CGFloat tipsLbHeight = layout.textBoundingSize.height;
  94. [self.tipsLb mas_updateConstraints:^(MASConstraintMaker *make) {
  95. make.height.mas_equalTo(tipsLbHeight);
  96. }];
  97. CGFloat versionUpdateCoverViewHeight = [self.versionUpdateCoverView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  98. CGFloat titleLbHeight = [self.titleLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  99. CGFloat buttonViewHeight = [self.buttonView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  100. self.frame = CGRectMake(0, 0, kFrameWidth*0.8, adapt(15) + versionUpdateCoverViewHeight + adapt(15) + titleLbHeight + adapt(15) + tipsLbHeight + adapt(15) + buttonViewHeight + adapt(15));
  101. }
  102. - (UIView *)baseView{
  103. if (!_baseView) {
  104. _baseView = [[UIView alloc]init];
  105. _baseView.backgroundColor = HexColorFromRGB(0xFFFFFF);
  106. }
  107. return _baseView;
  108. }
  109. - (UIImageView *)versionUpdateCoverView{
  110. if (!_versionUpdateCoverView) {
  111. _versionUpdateCoverView = [[UIImageView alloc]init];
  112. _versionUpdateCoverView.image = ImageByName(@"ym_common_update_version_cvoer");
  113. }
  114. return _versionUpdateCoverView;
  115. }
  116. - (UILabel *)titleLb{
  117. if (!_titleLb) {
  118. _titleLb = [[UILabel alloc]init];
  119. _titleLb.font = LCBoldFont(19);
  120. _titleLb.textColor = HexColorFromRGB(0x333333);
  121. _titleLb.textAlignment = NSTextAlignmentCenter;
  122. _titleLb.text = @"发现新版本";
  123. }
  124. return _titleLb;
  125. }
  126. - (YYLabel *)tipsLb{
  127. if (!_tipsLb) {
  128. _tipsLb = [[YYLabel alloc]init];
  129. _tipsLb.numberOfLines = 0;
  130. _tipsLb.font = LCFont(14);
  131. _tipsLb.textAlignment = NSTextAlignmentLeft;
  132. }
  133. return _tipsLb;
  134. }
  135. - (UIView *)buttonView{
  136. if (!_buttonView) {
  137. _buttonView = [[UIView alloc]init];
  138. }
  139. return _buttonView;
  140. }
  141. - (UIButton *)confirmBtn {
  142. if(!_confirmBtn){
  143. _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  144. _confirmBtn.backgroundColor = HexColorFromRGB(0xA7A9FD);
  145. _confirmBtn.titleLabel.font = LCFont(14);
  146. [_confirmBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:UIControlStateNormal];
  147. [_confirmBtn setTitle:@"立即升级" forState:UIControlStateNormal];
  148. _confirmBtn.layer.cornerRadius = adapt(40)/2;
  149. WS(weakSelf)
  150. [[[_confirmBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  151. if (weakSelf.buttonBlock) {
  152. weakSelf.buttonBlock(YES);
  153. }
  154. }];
  155. }
  156. return _confirmBtn;
  157. }
  158. - (UIButton *)cancelBtn {
  159. if(!_cancelBtn){
  160. _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  161. _cancelBtn.backgroundColor = UIColor.clearColor;
  162. _cancelBtn.titleLabel.font = LCFont(10);
  163. [_cancelBtn setTitleColor:HexColorFromRGB(0x999999) forState:UIControlStateNormal];
  164. [_cancelBtn setTitle:@"以后再说" forState:UIControlStateNormal];
  165. WS(weakSelf)
  166. [[[_cancelBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  167. if (weakSelf.buttonBlock) {
  168. weakSelf.buttonBlock(NO);
  169. }
  170. }];
  171. }
  172. return _cancelBtn;
  173. }
  174. @end