You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.8 KiB
107 lines
3.8 KiB
// |
|
// TFUpdateAlertView.m |
|
// TFReader |
|
// |
|
// Created by 谢腾飞 on 2020/12/17. |
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved. |
|
// |
|
|
|
#import "TFUpdateAlertView.h" |
|
|
|
@interface TFUpdateAlertView () |
|
|
|
@property (nonatomic ,strong) UIImageView *topImageView; |
|
|
|
@end |
|
|
|
@implementation TFUpdateAlertView |
|
|
|
- (void)createSubviews |
|
{ |
|
[super createSubviews]; |
|
|
|
self.closeButton.hidden = YES; |
|
self.showDivider = NO; |
|
self.contentScrollView.showsVerticalScrollIndicator = YES; |
|
|
|
[self addSubview:self.alertBackView]; |
|
|
|
self.topImageView = [[UIImageView alloc] init]; |
|
self.topImageView.image = [UIImage imageNamed:TFLocalizedString(@"alert_update_top")]; |
|
[self.alertBackView addSubview:self.topImageView]; |
|
[self.alertBackView sendSubviewToBack:self.topImageView]; |
|
|
|
self.alertTitle = @""; |
|
self.contentLabel.textAlignment = NSTextAlignmentLeft; |
|
|
|
self.cancelButton.backgroundColor = [UIColor clearColor]; |
|
[self.cancelButton setTitleColor:kColorRGBA(62, 120, 232, 1) forState:UIControlStateNormal]; |
|
self.cancelTitle = TFLocalizedString(@"再等等"); |
|
|
|
self.confirmButton.layer.cornerRadius = self.alertViewBtnHeight / 2; |
|
self.confirmButton.backgroundColor = kColorRGBA(62, 120, 232, 1); |
|
[self.confirmButton setTitleColor:kWhiteColor forState:UIControlStateNormal]; |
|
[self.alertBackView addSubview:self.confirmButton]; |
|
self.confirmTitle = TFLocalizedString(@"去更新"); |
|
} |
|
|
|
- (void)showAlertView |
|
{ |
|
[super showAlertView]; |
|
|
|
[self.alertBackView mas_updateConstraints:^(MASConstraintMaker *make) { |
|
make.bottom.mas_equalTo(self.confirmButton.mas_bottom).with.offset(kMargin); |
|
make.centerY.mas_equalTo(self.mas_centerY).with.offset(self.alertViewWidth * 0.12); |
|
}]; |
|
|
|
[self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.width.mas_equalTo(self.alertBackView.mas_width); |
|
make.height.mas_equalTo(self.alertBackView.mas_width).with.multipliedBy(0.4788); |
|
make.centerX.mas_equalTo(self.alertBackView.mas_centerX); |
|
make.bottom.mas_equalTo(self.alertBackView.mas_top).with.offset(kMargin); |
|
}]; |
|
|
|
CGFloat labelHeight = [TFViewHelper getDynamicHeightWithLabelFont:kMainFont labelWidth:SCREEN_WIDTH - 3 * kMargin labelText:self.alertDetailContent] + kMargin; |
|
|
|
if (labelHeight < self.alertViewWidth * 0.24) { |
|
labelHeight = self.alertViewWidth * 0.24; |
|
[self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) { |
|
make.height.mas_equalTo(labelHeight); |
|
}]; |
|
} else if (labelHeight > SCREEN_HEIGHT / 3) { |
|
labelHeight = SCREEN_HEIGHT / 3; |
|
} |
|
|
|
[self.contentScrollView mas_updateConstraints:^(MASConstraintMaker *make) { |
|
make.height.mas_equalTo(labelHeight); |
|
}]; |
|
|
|
[self.cancelButton mas_updateConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(self.alertBackView.mas_left).with.offset(kMargin); |
|
if (self.alertBtnType == TFAlertButtonTypeSingleConfirm) { |
|
make.width.mas_equalTo(CGFLOAT_MIN); |
|
} else { |
|
make.width.mas_equalTo(self.alertViewWidth / 2 - kMargin - kHalfMargin); |
|
} |
|
}]; |
|
|
|
[self.confirmButton mas_updateConstraints:^(MASConstraintMaker *make) { |
|
make.right.mas_equalTo(self.alertBackView.mas_right).with.offset(- kMargin); |
|
if (self.alertBtnType == TFAlertButtonTypeSingleCancel) { |
|
make.width.mas_equalTo(CGFLOAT_MIN); |
|
} else if (self.alertBtnType == TFAlertButtonTypeSingleConfirm) { |
|
make.width.mas_equalTo(self.alertViewWidth - 2 * kMargin); |
|
} else { |
|
make.width.mas_equalTo(self.alertViewWidth / 2 - kMargin - kHalfMargin); |
|
} |
|
}]; |
|
} |
|
|
|
- (void)setUpdateMessage:(NSString *)updateMessage |
|
{ |
|
_updateMessage = updateMessage; |
|
|
|
self.alertDetailContent = updateMessage; |
|
} |
|
|
|
@end
|
|
|