245 lines
7.9 KiB
Objective-C
245 lines
7.9 KiB
Objective-C
//
|
|
// KBAppUpdateView.m
|
|
// keyBoard
|
|
//
|
|
|
|
#import "KBAppUpdateView.h"
|
|
|
|
@interface KBAppUpdateView ()
|
|
@property (nonatomic, strong) UIImageView *backgroundImageView;
|
|
@property (nonatomic, strong) UILabel *titleLabel;
|
|
@property (nonatomic, strong) UIView *versionBadgeView;
|
|
@property (nonatomic, strong) UILabel *versionLabel;
|
|
@property (nonatomic, strong) UILabel *contentTitleLabel;
|
|
@property (nonatomic, strong) UILabel *contentLabel;
|
|
@property (nonatomic, strong) UIButton *upgradeButton;
|
|
@end
|
|
|
|
@implementation KBAppUpdateView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
if (self = [super initWithFrame:frame]) {
|
|
self.backgroundColor = [UIColor clearColor];
|
|
self.layer.cornerRadius = KBFit(22.0);
|
|
self.layer.masksToBounds = YES;
|
|
[self setupUI];
|
|
[self setupConstraints];
|
|
[self applyDefaultTexts];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initWithCoder:(NSCoder *)coder {
|
|
if (self = [super initWithCoder:coder]) {
|
|
self.backgroundColor = [UIColor whiteColor];
|
|
self.layer.cornerRadius = KBFit(22.0);
|
|
self.layer.masksToBounds = YES;
|
|
[self setupUI];
|
|
[self setupConstraints];
|
|
[self applyDefaultTexts];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - Setup
|
|
|
|
- (void)setupUI {
|
|
[self addSubview:self.backgroundImageView];
|
|
[self addSubview:self.titleLabel];
|
|
[self addSubview:self.versionBadgeView];
|
|
[self.versionBadgeView addSubview:self.versionLabel];
|
|
[self addSubview:self.contentTitleLabel];
|
|
[self addSubview:self.contentLabel];
|
|
[self addSubview:self.upgradeButton];
|
|
}
|
|
|
|
- (void)setupConstraints {
|
|
[self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self);
|
|
}];
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.equalTo(self).offset(KBFit(45.0));
|
|
make.top.equalTo(self).offset(KBFit(70.0));
|
|
make.right.lessThanOrEqualTo(self).offset(-KBFit(24.0));
|
|
}];
|
|
|
|
[self.versionBadgeView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.equalTo(self).offset(KBFit(45.0));
|
|
make.top.equalTo(self).offset(KBFit(120.0));
|
|
make.width.mas_equalTo(KBFit(73.0));
|
|
make.height.mas_equalTo(KBFit(23.0));
|
|
}];
|
|
|
|
[self.versionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self.versionBadgeView);
|
|
}];
|
|
|
|
[self.contentTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.equalTo(self).offset(KBFit(45.0));
|
|
make.top.equalTo(self).offset(KBFit(181.0));
|
|
make.right.lessThanOrEqualTo(self).offset(-KBFit(20.0));
|
|
}];
|
|
|
|
[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.equalTo(self).offset(KBFit(45.0));
|
|
make.top.equalTo(self.contentTitleLabel.mas_bottom).offset(KBFit(8.0));
|
|
make.right.lessThanOrEqualTo(self).offset(-KBFit(20.0));
|
|
make.bottom.lessThanOrEqualTo(self.upgradeButton.mas_top).offset(-KBFit(16.0));
|
|
}];
|
|
|
|
[self.upgradeButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.equalTo(self);
|
|
make.bottom.equalTo(self).offset(-KBFit(12.0));
|
|
make.width.mas_equalTo(KBFit(230.0));
|
|
make.height.mas_equalTo(KBFit(45.0));
|
|
}];
|
|
}
|
|
|
|
- (void)applyDefaultTexts {
|
|
self.titleText = KBLocalized(@"");
|
|
self.versionText = @"V1.1.4";
|
|
self.contentTitleText = KBLocalized(@"Ver. Update Content");
|
|
self.contentItems = @[
|
|
KBLocalized(@"AAAAAAAAAAAAAAAAAAA"),
|
|
KBLocalized(@"SSSSSSSSSSSSSSSSSSS")
|
|
];
|
|
self.upgradeButtonTitle = KBLocalized(@"立即升级");
|
|
}
|
|
|
|
#pragma mark - Actions
|
|
|
|
- (void)onTapUpgrade {
|
|
if ([self.delegate respondsToSelector:@selector(appUpdateViewDidTapUpgrade:)]) {
|
|
[self.delegate appUpdateViewDidTapUpgrade:self];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Setters
|
|
|
|
- (void)setBackgroundImageName:(NSString *)backgroundImageName {
|
|
_backgroundImageName = [backgroundImageName copy];
|
|
if (_backgroundImageName.length > 0) {
|
|
self.backgroundImageView.image = [UIImage imageNamed:_backgroundImageName];
|
|
} else {
|
|
self.backgroundImageView.image = nil;
|
|
}
|
|
}
|
|
|
|
- (void)setTitleText:(NSString *)titleText {
|
|
_titleText = [titleText copy];
|
|
self.titleLabel.text = _titleText;
|
|
}
|
|
|
|
- (void)setVersionText:(NSString *)versionText {
|
|
_versionText = [versionText copy];
|
|
self.versionLabel.text = _versionText;
|
|
}
|
|
|
|
- (void)setContentTitleText:(NSString *)contentTitleText {
|
|
_contentTitleText = [contentTitleText copy];
|
|
self.contentTitleLabel.text = _contentTitleText;
|
|
}
|
|
|
|
- (void)setContentItems:(NSArray<NSString *> *)contentItems {
|
|
_contentItems = [contentItems copy];
|
|
self.contentLabel.text = [self formattedContentItems:_contentItems];
|
|
}
|
|
|
|
- (void)setUpgradeButtonTitle:(NSString *)upgradeButtonTitle {
|
|
_upgradeButtonTitle = [upgradeButtonTitle copy];
|
|
[self.upgradeButton setTitle:_upgradeButtonTitle forState:UIControlStateNormal];
|
|
}
|
|
|
|
#pragma mark - Helpers
|
|
|
|
- (NSString *)formattedContentItems:(NSArray<NSString *> *)items {
|
|
if (items.count == 0) {
|
|
return @"";
|
|
}
|
|
NSMutableArray<NSString *> *lines = [NSMutableArray array];
|
|
[items enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) {
|
|
if (![obj isKindOfClass:[NSString class]] || obj.length == 0) {
|
|
return;
|
|
}
|
|
NSString *line = [NSString stringWithFormat:@"%lu、%@", (unsigned long)(idx + 1), obj];
|
|
[lines addObject:line];
|
|
}];
|
|
return [lines componentsJoinedByString:@"\n"];
|
|
}
|
|
|
|
#pragma mark - Lazy
|
|
|
|
- (UIImageView *)backgroundImageView {
|
|
if (!_backgroundImageView) {
|
|
_backgroundImageView = [[UIImageView alloc] init];
|
|
_backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
_backgroundImageView.clipsToBounds = YES;
|
|
}
|
|
return _backgroundImageView;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.numberOfLines = 0;
|
|
_titleLabel.font = [KBFont bold:26.0];
|
|
_titleLabel.textColor = [UIColor colorWithHex:0xF6FCFF];
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (UIView *)versionBadgeView {
|
|
if (!_versionBadgeView) {
|
|
_versionBadgeView = [[UIView alloc] init];
|
|
_versionBadgeView.backgroundColor = [UIColor colorWithHex:0xFFDE67];
|
|
_versionBadgeView.layer.cornerRadius = KBFit(11.5);
|
|
_versionBadgeView.layer.masksToBounds = YES;
|
|
}
|
|
return _versionBadgeView;
|
|
}
|
|
|
|
- (UILabel *)versionLabel {
|
|
if (!_versionLabel) {
|
|
_versionLabel = [[UILabel alloc] init];
|
|
_versionLabel.font = [KBFont regular:14.0];
|
|
_versionLabel.textColor = [UIColor colorWithHex:0x3D3D3D];
|
|
_versionLabel.textAlignment = NSTextAlignmentCenter;
|
|
}
|
|
return _versionLabel;
|
|
}
|
|
|
|
- (UILabel *)contentTitleLabel {
|
|
if (!_contentTitleLabel) {
|
|
_contentTitleLabel = [[UILabel alloc] init];
|
|
_contentTitleLabel.font = [KBFont regular:18.0];
|
|
_contentTitleLabel.textColor = [UIColor colorWithHex:0x085E59];
|
|
}
|
|
return _contentTitleLabel;
|
|
}
|
|
|
|
- (UILabel *)contentLabel {
|
|
if (!_contentLabel) {
|
|
_contentLabel = [[UILabel alloc] init];
|
|
_contentLabel.numberOfLines = 0;
|
|
_contentLabel.font = [KBFont medium:13.0];
|
|
_contentLabel.textColor = [UIColor colorWithHex:0x085E59];
|
|
}
|
|
return _contentLabel;
|
|
}
|
|
|
|
- (UIButton *)upgradeButton {
|
|
if (!_upgradeButton) {
|
|
_upgradeButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
_upgradeButton.backgroundColor = [UIColor colorWithHex:0x002339];
|
|
_upgradeButton.layer.cornerRadius = KBFit(22.5);
|
|
_upgradeButton.layer.masksToBounds = YES;
|
|
_upgradeButton.titleLabel.font = [KBFont bold:14.0];
|
|
[_upgradeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
[_upgradeButton addTarget:self action:@selector(onTapUpgrade) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _upgradeButton;
|
|
}
|
|
|
|
@end
|