123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- //
- // YMVersionUpdatePopupView.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/3/21.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMVersionUpdatePopupView.h"
- @interface YMVersionUpdatePopupView ()
- /** 基础视图*/
- @property (nonatomic, strong) UIView *baseView;
- /** 版本更新封面图*/
- @property (nonatomic, strong) UIImageView *versionUpdateCoverView;
- /** 标题标签*/
- @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;
- /** 单确认按钮*/
- @property (nonatomic, strong) UIButton *singleConfirmBtn;
- @end
- @implementation YMVersionUpdatePopupView
- - (void)ym_setupViews{
-
- [self addSubview:self.baseView];
- [self addSubview:self.versionUpdateCoverView];
- [self.baseView addSubview:self.titleLb];
- [self.baseView addSubview:self.tipsLb];
- [self.baseView addSubview:self.buttonView];
- [self.buttonView addSubview:self.cancelBtn];
- [self.buttonView addSubview:self.confirmBtn];
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints{
-
- [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.versionUpdateCoverView).offset(adapt(35));
- make.left.equalTo(self);
- make.right.equalTo(self);
- make.bottom.equalTo(self);
- }];
-
- [self.versionUpdateCoverView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self);
- make.left.equalTo(self.baseView);
- make.right.equalTo(self.baseView);
- make.height.mas_equalTo(adapt(200));
- }];
-
- [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.versionUpdateCoverView.mas_bottom).offset(adapt(15));
- make.left.equalTo(self.baseView).offset(adapt(30));
- make.right.equalTo(self.baseView).offset(adapt(-30));
- }];
-
- [self.tipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.titleLb.mas_bottom).offset(adapt(15));
- make.left.equalTo(self).offset(adapt(30));
- make.right.equalTo(self).offset(adapt(-30));
- }];
-
- [self.buttonView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.tipsLb.mas_bottom).offset(adapt(15));
- make.left.equalTo(self);
- make.right.equalTo(self);
- make.bottom.equalTo(self).offset(adapt(-15));
- make.height.mas_equalTo(adapt(110));
- }];
-
- NSArray *btnArr = @[self.confirmBtn,self.cancelBtn];
-
- // 实现masonry水平固定控件宽度方法
- // axisType 横排还是竖排
- // fixedSpacing 两个控件间隔
- // leadSpacing 第一个控件与边缘的间隔
- // tailSpacing 最后一个控件与边缘的间隔
- [btnArr mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:adapt(10) leadSpacing:adapt(10) tailSpacing:adapt(10)];
-
- // 设置array的垂直方向的约束
- [btnArr mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.buttonView).offset(adapt(50));
- make.right.equalTo(self.buttonView).offset(adapt(-50));
- }];
-
- [super updateConstraints];
- }
- - (void)configutationWithTips:(NSString *)tipsStr{
-
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:tipsStr];
- attributedString.yy_font = LCFont(15);
- attributedString.yy_color = HexColorFromRGB(0x333333);
- attributedString.yy_lineSpacing = adapt(5);
- attributedString.yy_alignment = NSTextAlignmentLeft;
-
- self.tipsLb.attributedText = attributedString;
-
- CGSize introSize = CGSizeMake(kFrameWidth*0.8 - adapt(30)*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 versionUpdateCoverViewHeight = [self.versionUpdateCoverView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
-
- CGFloat titleLbHeight = [self.titleLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
-
- CGFloat buttonViewHeight = [self.buttonView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
-
- self.frame = CGRectMake(0, 0, kFrameWidth*0.8, adapt(15) + versionUpdateCoverViewHeight + adapt(15) + titleLbHeight + adapt(15) + tipsLbHeight + adapt(15) + buttonViewHeight + adapt(15));
- }
- - (UIView *)baseView{
- if (!_baseView) {
- _baseView = [[UIView alloc]init];
- _baseView.backgroundColor = HexColorFromRGB(0xFFFFFF);
- }
- return _baseView;
- }
- - (UIImageView *)versionUpdateCoverView{
- if (!_versionUpdateCoverView) {
- _versionUpdateCoverView = [[UIImageView alloc]init];
- _versionUpdateCoverView.image = ImageByName(@"ym_common_update_version_cvoer");
- }
- return _versionUpdateCoverView;
- }
- - (UILabel *)titleLb{
- if (!_titleLb) {
- _titleLb = [[UILabel alloc]init];
- _titleLb.font = LCBoldFont(19);
- _titleLb.textColor = HexColorFromRGB(0x333333);
- _titleLb.textAlignment = NSTextAlignmentCenter;
- _titleLb.text = @"发现新版本";
- }
- return _titleLb;
- }
- - (YYLabel *)tipsLb{
- if (!_tipsLb) {
- _tipsLb = [[YYLabel alloc]init];
- _tipsLb.numberOfLines = 0;
- _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.backgroundColor = HexColorFromRGB(0xA7A9FD);
- _confirmBtn.titleLabel.font = LCFont(14);
- [_confirmBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:UIControlStateNormal];
- [_confirmBtn setTitle:@"立即升级" forState:UIControlStateNormal];
- _confirmBtn.layer.cornerRadius = adapt(40)/2;
- WS(weakSelf)
- [[[_confirmBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- if (weakSelf.buttonBlock) {
- weakSelf.buttonBlock(YES);
- }
-
- }];
- }
- return _confirmBtn;
- }
- - (UIButton *)cancelBtn {
- if(!_cancelBtn){
- _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _cancelBtn.backgroundColor = UIColor.clearColor;
- _cancelBtn.titleLabel.font = LCFont(10);
- [_cancelBtn setTitleColor:HexColorFromRGB(0x999999) forState:UIControlStateNormal];
- [_cancelBtn setTitle:@"以后再说" forState:UIControlStateNormal];
- WS(weakSelf)
- [[[_cancelBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- if (weakSelf.buttonBlock) {
- weakSelf.buttonBlock(NO);
- }
- }];
- }
- return _cancelBtn;
- }
- @end
|