YMGuestUnlockPopupView.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. //
  2. // YMGuestUnlockPopupView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/2.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMGuestUnlockPopupView.h"
  9. @interface YMGuestUnlockPopupView ()
  10. /** 解锁提示视图*/
  11. @property (nonatomic, strong) UIImageView *unlockTipsView;
  12. /** 提示标题标签*/
  13. @property (nonatomic, strong) UILabel *tipsTitleLb;
  14. /** 提示详情标签*/
  15. @property (nonatomic, strong) UILabel *tipsDetailLb;
  16. /** 按钮视图*/
  17. @property (nonatomic, strong) UIView *buttonView;
  18. /** 确认按钮*/
  19. @property (nonatomic, strong) UIButton *confirmBtn;
  20. /** 取消按钮*/
  21. @property (nonatomic, strong) UIButton *cancelBtn;
  22. @end
  23. @implementation YMGuestUnlockPopupView
  24. - (void)ym_setupViews{
  25. self.backgroundColor = HexColorFromRGB(0xFFFFFF);
  26. [self addSubview:self.unlockTipsView];
  27. [self addSubview:self.tipsTitleLb];
  28. [self addSubview:self.tipsDetailLb];
  29. [self addSubview:self.buttonView];
  30. [self.buttonView addSubview:self.confirmBtn];
  31. [self.buttonView addSubview:self.cancelBtn];
  32. [self setNeedsUpdateConstraints];
  33. [self updateConstraintsIfNeeded];
  34. [self configurationFrame];
  35. }
  36. - (void)updateConstraints{
  37. [self.unlockTipsView mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.centerX.equalTo(self.mas_centerX);
  39. make.top.equalTo(self).offset(adapt(30));
  40. make.width.mas_equalTo(adapt(260));
  41. make.height.mas_equalTo(adapt(173));
  42. }];
  43. [self.tipsTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.top.equalTo(self.unlockTipsView.mas_bottom).offset(adapt(10));
  45. make.left.equalTo(self).offset(adapt(20));
  46. make.right.equalTo(self).offset(adapt(-20));
  47. }];
  48. [self.tipsDetailLb mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.top.equalTo(self.tipsTitleLb.mas_bottom).offset(adapt(20));
  50. make.left.equalTo(self).offset(adapt(20));
  51. make.right.equalTo(self).offset(adapt(-20));
  52. }];
  53. [self.buttonView mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.equalTo(self.tipsDetailLb.mas_bottom).offset(adapt(10));
  55. make.left.equalTo(self);
  56. make.right.equalTo(self);
  57. make.bottom.equalTo(self).offset(adapt(-10)).priorityHigh();
  58. make.height.mas_equalTo(adapt(100));
  59. }];
  60. NSArray *btnArr = @[self.confirmBtn,self.cancelBtn];
  61. // 实现masonry水平固定控件宽度方法
  62. // axisType 横排还是竖排
  63. // fixedSpacing 两个控件间隔
  64. // leadSpacing 第一个控件与边缘的间隔
  65. // tailSpacing 最后一个控件与边缘的间隔
  66. [btnArr mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:adapt(10) leadSpacing:adapt(5) tailSpacing:adapt(5)];
  67. // 设置array的垂直方向的约束
  68. [btnArr mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.centerX.equalTo(self.mas_centerX);
  70. make.width.mas_equalTo(adapt(200));
  71. }];
  72. [super updateConstraints];
  73. }
  74. - (void)configurationFrame{
  75. CGFloat unlockTipsViewHeight = [self.unlockTipsView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  76. CGFloat tipsTitleLbHeight = [self.tipsTitleLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  77. CGFloat tipsDetailLbHeight = [self.tipsDetailLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  78. CGFloat buttonViewHeight = [self.buttonView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  79. self.frame = CGRectMake(0, 0, kFrameWidth*0.85, adapt(30) + unlockTipsViewHeight + adapt(10) + tipsTitleLbHeight + adapt(20) + tipsDetailLbHeight + adapt(10) + buttonViewHeight + adapt(10));
  80. }
  81. #pragma mark - lazyload
  82. - (UIImageView *)unlockTipsView{
  83. if (!_unlockTipsView) {
  84. _unlockTipsView = [[UIImageView alloc]init];
  85. _unlockTipsView.image = ImageByName(@"ym_guest_unlock_tips_icon");
  86. }
  87. return _unlockTipsView;
  88. }
  89. - (UILabel *)tipsTitleLb{
  90. if (!_tipsTitleLb) {
  91. _tipsTitleLb = [[UILabel alloc]init];
  92. _tipsTitleLb.font = LCBoldFont(17);
  93. _tipsTitleLb.textColor = HexColorFromRGB(0x333333);
  94. _tipsTitleLb.textAlignment = NSTextAlignmentCenter;
  95. _tipsTitleLb.text = @"解锁访客记录";
  96. }
  97. return _tipsTitleLb;
  98. }
  99. - (UILabel *)tipsDetailLb{
  100. if (!_tipsDetailLb) {
  101. _tipsDetailLb = [[UILabel alloc]init];
  102. _tipsDetailLb.font = LCFont(13);
  103. _tipsDetailLb.textColor = HexColorFromRGB(0x999999);
  104. _tipsDetailLb.textAlignment = NSTextAlignmentCenter;
  105. _tipsDetailLb.text = @"开通VIP会员,不错过每一段缘分";
  106. }
  107. return _tipsDetailLb;
  108. }
  109. - (UIView *)buttonView{
  110. if (!_buttonView) {
  111. _buttonView = [[UIView alloc]init];
  112. }
  113. return _buttonView;
  114. }
  115. - (UIButton *)confirmBtn {
  116. if(!_confirmBtn){
  117. _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  118. _confirmBtn.titleLabel.font = LCFont(15);
  119. [_confirmBtn setTitle:@"立即开通" forState:UIControlStateNormal];
  120. [_confirmBtn setTitleColor:HexColorFromRGB(0x622d0d) forState:UIControlStateNormal];
  121. _confirmBtn.layer.cornerRadius = adapt(10);
  122. [_confirmBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  123. WS(weakSelf)
  124. [[[_confirmBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  125. if (weakSelf.buttonBlock) {
  126. weakSelf.buttonBlock(YES);
  127. }
  128. }];
  129. }
  130. return _confirmBtn;
  131. }
  132. - (UIButton *)cancelBtn {
  133. if(!_cancelBtn){
  134. _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  135. _cancelBtn.titleLabel.font = LCFont(13);
  136. [_cancelBtn setTitle:@"再想想" forState:UIControlStateNormal];
  137. [_cancelBtn setTitleColor:HexColorFromRGB(0x555555) forState:UIControlStateNormal];
  138. WS(weakSelf)
  139. [[[_cancelBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  140. if (weakSelf.buttonBlock) {
  141. weakSelf.buttonBlock(NO);
  142. }
  143. }];
  144. }
  145. return _cancelBtn;
  146. }
  147. @end