Files
yinmeng-ios/xplan-ios/Main/Tabbar/View/VersionUpdate/XPUpgradeView.m
2022-12-23 10:44:00 +08:00

160 lines
5.3 KiB
Objective-C

//
// XPUpgradeView.m
// xplan-ios
//
// Created by GreenLand on 2022/12/5.
//
#import "XPUpgradeView.h"
#import <Masonry/Masonry.h>
#import <SZTextView/SZTextView.h>
#import "UIImage+Utils.h"
#import "XPMacro.h"
#import "ThemeColor.h"
#import "UIView+Corner.h"
#import "TTPopup.h"
@interface XPUpgradeView()
@property (nonatomic,strong) UIImageView *bgImageView;
@property (nonatomic,strong) SZTextView *textView;
///容器
@property (nonatomic,strong) UIStackView *stackView;
@property (nonatomic,strong) UIButton *updateBtn;
@property (nonatomic,strong) UIButton *cancelBtn;
@end
@implementation XPUpgradeView
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
[self addSubview:self.bgImageView];
[self.bgImageView addSubview:self.textView];
[self.bgImageView addSubview:self.stackView];
[self.stackView addArrangedSubview:self.cancelBtn];
[self.stackView addArrangedSubview:self.updateBtn];
}
- (void)initSubViewConstraints {
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self);
make.width.mas_equalTo(250);
make.height.mas_greaterThanOrEqualTo(311);
}];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(32);
make.centerX.mas_equalTo(self.bgImageView);
make.bottom.mas_equalTo(self.bgImageView).offset(-20);
}];
[self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(106);
}];
[self.updateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(106);
}];
[self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.bgImageView.mas_top).mas_offset(136);
make.left.mas_equalTo(17);
make.right.mas_equalTo(-17);
make.bottom.equalTo(self.stackView.mas_top).offset(-5);
}];
}
-(void)setVersionModel:(XPVersionUpdateModel *)versionModel{
_versionModel = versionModel;
_textView.text = _versionModel.updateVersionDesc;
_cancelBtn.hidden = _versionModel.updateStatus == 3;
}
-(void)updateAction{
NSURL *url = [[NSURL alloc]initWithString:self.versionModel.updateDownloadLink];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
if(self.versionModel.updateStatus != 3){
[TTPopup dismiss];
}
}];
}
}
-(void)cancelAction{
[TTPopup dismiss];
}
#pragma mark - 懒加载
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentFill;
_stackView.spacing = 10;
}
return _stackView;
}
- (UIImageView *)bgImageView{
if (!_bgImageView){
_bgImageView = [UIImageView new];
_bgImageView.backgroundColor = [UIColor clearColor];
_bgImageView.userInteractionEnabled = YES;
_bgImageView.image = [UIImage imageNamed:@"version_update_bg"];
}
return _bgImageView;
}
- (SZTextView *)textView {
if (!_textView) {
_textView = [[SZTextView alloc] init];
_textView.textColor = [ThemeColor mainTextColor];
_textView.font = [UIFont systemFontOfSize:12];
_textView.backgroundColor = [UIColor clearColor];
_textView.editable = NO;
}
return _textView;
}
-(UIButton *)updateBtn{
if (!_updateBtn){
UIImage *image = [UIImage gradientColorImageFromColors:@[[ThemeColor confirmButtonGradientStartColor],[ThemeColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)];
_updateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_updateBtn setTitle:@"记录更新" forState:UIControlStateNormal];
_updateBtn.titleLabel.font = [UIFont systemFontOfSize:14];
_updateBtn.titleLabel.textColor = [ThemeColor confirmButtonTextColor];
[_updateBtn setBackgroundImage:image forState:UIControlStateNormal];
_updateBtn.layer.cornerRadius = 32 / 2;
_updateBtn.layer.masksToBounds = YES;
[_updateBtn addTarget:self action:@selector(updateAction) forControlEvents:UIControlEventTouchUpInside];
}
return _updateBtn;
}
-(UIButton *)cancelBtn{
if (!_cancelBtn){
_cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *image = [UIImage gradientColorImageFromColors:@[[ThemeColor cancelButtonGradientStartColor],[ThemeColor cancelButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)];
[_cancelBtn setTitle:@"下次再说" forState:UIControlStateNormal];
_cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14];
_cancelBtn.titleLabel.textColor = [ThemeColor cancelButtonTextColor];
[_cancelBtn setBackgroundImage:image forState:UIControlStateNormal];
_cancelBtn.layer.cornerRadius = 32 / 2;
_cancelBtn.layer.masksToBounds = YES;
[_cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
}
return _cancelBtn;
}
@end