// // YMGuestUnlockPopupView.m // MSYOUPAI // // Created by YoMi on 2024/3/2. // Copyright © 2024 MS. All rights reserved. // #import "YMGuestUnlockPopupView.h" @interface YMGuestUnlockPopupView () /** 解锁提示视图*/ @property (nonatomic, strong) UIImageView *unlockTipsView; /** 提示标题标签*/ @property (nonatomic, strong) UILabel *tipsTitleLb; /** 提示详情标签*/ @property (nonatomic, strong) UILabel *tipsDetailLb; /** 按钮视图*/ @property (nonatomic, strong) UIView *buttonView; /** 确认按钮*/ @property (nonatomic, strong) UIButton *confirmBtn; /** 取消按钮*/ @property (nonatomic, strong) UIButton *cancelBtn; @end @implementation YMGuestUnlockPopupView - (void)ym_setupViews{ self.backgroundColor = HexColorFromRGB(0xFFFFFF); [self addSubview:self.unlockTipsView]; [self addSubview:self.tipsTitleLb]; [self addSubview:self.tipsDetailLb]; [self addSubview:self.buttonView]; [self.buttonView addSubview:self.confirmBtn]; [self.buttonView addSubview:self.cancelBtn]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; [self configurationFrame]; } - (void)updateConstraints{ [self.unlockTipsView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.mas_centerX); make.top.equalTo(self).offset(adapt(30)); make.width.mas_equalTo(adapt(260)); make.height.mas_equalTo(adapt(173)); }]; [self.tipsTitleLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.unlockTipsView.mas_bottom).offset(adapt(10)); make.left.equalTo(self).offset(adapt(20)); make.right.equalTo(self).offset(adapt(-20)); }]; [self.tipsDetailLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.tipsTitleLb.mas_bottom).offset(adapt(20)); make.left.equalTo(self).offset(adapt(20)); make.right.equalTo(self).offset(adapt(-20)); }]; [self.buttonView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.tipsDetailLb.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)configurationFrame{ CGFloat unlockTipsViewHeight = [self.unlockTipsView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height; CGFloat tipsTitleLbHeight = [self.tipsTitleLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height; CGFloat tipsDetailLbHeight = [self.tipsDetailLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height; CGFloat buttonViewHeight = [self.buttonView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height; self.frame = CGRectMake(0, 0, kFrameWidth*0.85, adapt(30) + unlockTipsViewHeight + adapt(10) + tipsTitleLbHeight + adapt(20) + tipsDetailLbHeight + adapt(10) + buttonViewHeight + adapt(10)); } #pragma mark - lazyload - (UIImageView *)unlockTipsView{ if (!_unlockTipsView) { _unlockTipsView = [[UIImageView alloc]init]; _unlockTipsView.image = ImageByName(@"ym_guest_unlock_tips_icon"); } return _unlockTipsView; } - (UILabel *)tipsTitleLb{ if (!_tipsTitleLb) { _tipsTitleLb = [[UILabel alloc]init]; _tipsTitleLb.font = LCBoldFont(17); _tipsTitleLb.textColor = HexColorFromRGB(0x333333); _tipsTitleLb.textAlignment = NSTextAlignmentCenter; _tipsTitleLb.text = @"解锁访客记录"; } return _tipsTitleLb; } - (UILabel *)tipsDetailLb{ if (!_tipsDetailLb) { _tipsDetailLb = [[UILabel alloc]init]; _tipsDetailLb.font = LCFont(13); _tipsDetailLb.textColor = HexColorFromRGB(0x999999); _tipsDetailLb.textAlignment = NSTextAlignmentCenter; _tipsDetailLb.text = @"开通VIP会员,不错过每一段缘分"; } return _tipsDetailLb; } - (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:HexColorFromRGB(0x622d0d) forState:UIControlStateNormal]; _confirmBtn.layer.cornerRadius = adapt(10); [_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