内更新弹窗
This commit is contained in:
229
xplan-ios/Main/Tabbar/View/VersionUpdate/XPUpgradeView.m
Normal file
229
xplan-ios/Main/Tabbar/View/VersionUpdate/XPUpgradeView.m
Normal file
@@ -0,0 +1,229 @@
|
||||
//
|
||||
// XPUpgradeView.m
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by GreenLand on 2022/12/5.
|
||||
//
|
||||
|
||||
#import "XPUpgradeView.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
#import "UIImage+Utils.h"
|
||||
#import "XPMacro.h"
|
||||
#import "ThemeColor.h"
|
||||
#import "UIView+Corner.h"
|
||||
|
||||
@interface XPUpgradeView()
|
||||
@property (nonatomic,strong) UIImageView *bgImageView;
|
||||
@property (nonatomic,strong) UIImageView *bgheadImageView;
|
||||
@property (nonatomic,strong) UIImageView *bgFooderImageView;
|
||||
@property (nonatomic,strong) UIView *titleBgView;
|
||||
@property (nonatomic,strong) UILabel *titleView;
|
||||
@property (nonatomic,strong) UILabel *versionView;
|
||||
@property (nonatomic,strong) UILabel *textView;
|
||||
@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.bgheadImageView];
|
||||
[self.bgImageView addSubview:self.bgFooderImageView];
|
||||
[self.bgImageView addSubview:self.titleBgView];
|
||||
[self.bgImageView addSubview:self.titleView];
|
||||
[self.bgImageView addSubview:self.versionView];
|
||||
[self.bgImageView addSubview:self.textView];
|
||||
[self.bgImageView addSubview:self.updateBtn];
|
||||
[self.bgImageView addSubview:self.cancelBtn];
|
||||
}
|
||||
- (void)initSubViewConstraints {
|
||||
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.center.equalTo(self);
|
||||
make.width.mas_equalTo(279);
|
||||
make.height.mas_greaterThanOrEqualTo(348);
|
||||
}];
|
||||
[self.bgheadImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.top.right.equalTo(self.bgImageView);
|
||||
make.height.mas_equalTo(125);
|
||||
}];
|
||||
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(99);
|
||||
make.centerX.equalTo(self.bgImageView);
|
||||
make.height.mas_equalTo(24);
|
||||
}];
|
||||
[self.versionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.titleView.mas_bottom).mas_offset(3);
|
||||
make.height.mas_equalTo(21);
|
||||
make.centerX.equalTo(self.bgImageView);
|
||||
}];
|
||||
[self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(self.bgImageView);
|
||||
make.width.mas_equalTo(50);
|
||||
make.height.mas_equalTo(17);
|
||||
make.bottom.equalTo(self.bgImageView.mas_bottom).mas_offset(-18);
|
||||
}];
|
||||
[self.updateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(154);
|
||||
make.height.mas_equalTo(34);
|
||||
make.centerX.equalTo(self.bgImageView);
|
||||
make.bottom.equalTo(self.bgImageView.mas_bottom).mas_offset(-43);
|
||||
}];
|
||||
|
||||
[self.bgFooderImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(18);
|
||||
make.width.mas_equalTo(250);
|
||||
make.height.mas_equalTo(227);
|
||||
make.bottom.equalTo(self.bgImageView);
|
||||
}];
|
||||
|
||||
[self.titleBgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.width.equalTo(self.bgFooderImageView);
|
||||
make.width.mas_equalTo(279);
|
||||
make.top.equalTo(self.bgheadImageView.mas_bottom);
|
||||
make.height.greaterThanOrEqualTo(@20);
|
||||
make.bottom.equalTo(self.textView);
|
||||
|
||||
}];
|
||||
[self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.equalTo(self.bgImageView.mas_bottom).mas_offset(-121);
|
||||
make.left.mas_equalTo(39);
|
||||
make.right.mas_equalTo(-40);
|
||||
make.top.equalTo(self.versionView.mas_bottom).mas_equalTo(9);
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
-(void)setVersionModel:(XPVersionUpdateModel *)versionModel{
|
||||
_versionModel = versionModel;
|
||||
_versionView.text = _versionModel.updateVersion;
|
||||
_textView.text = _versionModel.updateVersionDesc;
|
||||
_cancelBtn.hidden = _versionModel.updateStatus == 3;
|
||||
if(_versionModel.updateStatus == 3){
|
||||
[self.updateBtn mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.equalTo(self.bgImageView.mas_bottom).mas_offset(-21.5);
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
-(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){
|
||||
[self removeFromSuperview];
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
-(void)cancelAction{
|
||||
[self removeFromSuperview];
|
||||
}
|
||||
#pragma mark - 懒加载
|
||||
|
||||
- (UIImageView *)bgImageView{
|
||||
if (!_bgImageView){
|
||||
_bgImageView = [UIImageView new];
|
||||
_bgImageView.backgroundColor = [UIColor clearColor];
|
||||
_bgImageView.userInteractionEnabled = YES;
|
||||
}
|
||||
return _bgImageView;
|
||||
}
|
||||
- (UIImageView *)bgheadImageView{
|
||||
if (!_bgheadImageView){
|
||||
_bgheadImageView = [UIImageView new];
|
||||
_bgheadImageView.image = [UIImage imageNamed:@"tab_upgrade_head_view"];
|
||||
_bgheadImageView.userInteractionEnabled = YES;
|
||||
}
|
||||
return _bgheadImageView;
|
||||
}
|
||||
-(UIImageView *)bgFooderImageView{
|
||||
if (!_bgFooderImageView){
|
||||
_bgFooderImageView = [UIImageView new];
|
||||
UIImage *image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xFFFFFF),UIColorFromRGB(0xFFFFFF),UIColorFromRGB(0xE1FCFF)] gradientType:GradientTypeTopToBottom imgSize:CGSizeMake(250, 227)];
|
||||
_bgFooderImageView.image = image;
|
||||
_bgFooderImageView.userInteractionEnabled = YES;
|
||||
[_bgFooderImageView setCornerWithLeftTopCorner:0 rightTopCorner:0 bottomLeftCorner:25 bottomRightCorner:25 size:CGSizeMake(250, 227)];
|
||||
}
|
||||
return _bgFooderImageView;
|
||||
}
|
||||
- (UIView *)titleBgView{
|
||||
if (!_titleBgView){
|
||||
_titleBgView = [UIView new];
|
||||
_titleBgView.backgroundColor = [UIColor whiteColor];
|
||||
}
|
||||
return _titleBgView;
|
||||
}
|
||||
- (UILabel *)titleView{
|
||||
if (!_titleView){
|
||||
_titleView = [[UILabel alloc] init];
|
||||
_titleView.text = @"";
|
||||
_titleView.font = [UIFont systemFontOfSize:17 weight:UIFontWeightBold];
|
||||
// _titleView.textColor = [ThemeColor inputTextColor];
|
||||
// labelInitWithText:XCLocalizedString(@"XPUpgradeView0") font:[UIFont systemFontOfSize:17 weight:UIFontWeightBold] textColor:[ThemeColor inputTextColor]];
|
||||
_titleView.textAlignment = NSTextAlignmentCenter;
|
||||
}
|
||||
return _titleView;
|
||||
}
|
||||
|
||||
-(UILabel *)versionView{
|
||||
if (!_versionView){
|
||||
_versionView = [[UILabel alloc] init];
|
||||
_versionView.text = @"";
|
||||
_versionView.font = [UIFont systemFontOfSize:15 weight:UIFontWeightBold];
|
||||
// _versionView = [UILabel labelInitWithText:@"" font:[UIFont systemFontOfSize:15 weight:UIFontWeightBold] textColor:[ThemeColor inputTextColor]];
|
||||
_versionView.textAlignment = NSTextAlignmentCenter;
|
||||
}
|
||||
return _versionView;
|
||||
}
|
||||
-(UILabel *)textView{
|
||||
if (!_textView){
|
||||
_textView = [[UILabel alloc]init];
|
||||
_textView.textColor = UIColorFromRGB(0x6D6B89);
|
||||
_textView.font = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
|
||||
_textView.backgroundColor = [UIColor clearColor];
|
||||
_textView.numberOfLines = 0;
|
||||
|
||||
}
|
||||
return _textView;
|
||||
}
|
||||
-(UIButton *)updateBtn{
|
||||
if (!_updateBtn){
|
||||
UIImage *image = [UIImage gradientColorImageFromColors:@[[ThemeColor confirmButtonGradientStartColor],[ThemeColor confirmButtonGradientStartColor],[ThemeColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(154, 34)];
|
||||
_updateBtn = [[UIButton alloc] init];
|
||||
[_updateBtn setTitle:@"" forState:UIControlStateNormal];
|
||||
_updateBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
||||
_updateBtn.titleLabel.textColor = [UIColor whiteColor];
|
||||
[_updateBtn setBackgroundImage:image forState:UIControlStateNormal];
|
||||
// _updateBtn = [UIButton buttonInitWithText:XCLocalizedString(@"XPUpgradeView1") font:kFontRegular(14) textColor:[UIColor whiteColor] image:nil bgImage:image];
|
||||
_updateBtn.layer.cornerRadius = 34 / 2;
|
||||
_updateBtn.layer.masksToBounds = YES;
|
||||
[_updateBtn addTarget:self action:@selector(updateAction) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _updateBtn;
|
||||
}
|
||||
-(UIButton *)cancelBtn{
|
||||
if (!_cancelBtn){
|
||||
_cancelBtn = [[UIButton alloc] init];
|
||||
[_cancelBtn setTitle:@"" forState:UIControlStateNormal];
|
||||
_cancelBtn.titleLabel.font = [UIFont systemFontOfSize:12];
|
||||
_cancelBtn.titleLabel.textColor = [ThemeColor disableButtonTextColor];
|
||||
// _cancelBtn = [UIButton buttonInitWithText:XCLocalizedString(@"XPUpgradeView2") font:[UIFont systemFontOfSize:12 weight:UIFontWeightRegular] textColor:[ThemeColor disableButtonTextColor] image:nil bgImage:nil];
|
||||
[_cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _cancelBtn;
|
||||
|
||||
}
|
||||
|
||||
@end
|
Reference in New Issue
Block a user