Files
keyboard/keyBoard/Class/Me/V/KBSkinBottomActionView.m

177 lines
6.1 KiB
Mathematica
Raw Normal View History

2025-11-10 15:29:21 +08:00
//
// KBSkinBottomActionView.m
// keyBoard
//
//
#import "KBSkinBottomActionView.h"
@interface KBSkinBottomActionView ()
2025-12-11 16:39:22 +08:00
@property (nonatomic, strong) UIView *contentView; // 使
@property (nonatomic, strong) UIStackView *stackView; // Title/Icon/Price
@property (nonatomic, strong) UILabel *titleLabel; //
2025-11-10 15:29:21 +08:00
@property (nonatomic, strong) UIImageView *coinImageView; //
2025-12-11 16:39:22 +08:00
@property (nonatomic, strong) UILabel *priceLabel; //
2025-11-10 15:29:21 +08:00
@end
@implementation KBSkinBottomActionView
+ (CGFloat)preferredHeight { return 45.0; }
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
2025-11-10 19:51:23 +08:00
self.backgroundColor = [UIColor colorWithHex:KBColorValue];
2025-11-10 15:29:21 +08:00
self.layer.masksToBounds = YES; //
//
[self addTarget:self action:@selector(onTouchDown) forControlEvents:UIControlEventTouchDown];
[self addTarget:self action:@selector(onTouchUp) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside | UIControlEventTouchCancel];
// /
[self addSubview:self.contentView];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.centerY.equalTo(self);
//
make.left.greaterThanOrEqualTo(self).offset(16);
make.right.lessThanOrEqualTo(self).offset(-16);
}];
// Title - Icon - Price
2025-12-11 16:39:22 +08:00
[self.contentView addSubview:self.stackView];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.contentView);
2025-11-10 15:29:21 +08:00
}];
2025-12-11 16:39:22 +08:00
[self.stackView addArrangedSubview:self.titleLabel];
[self.stackView addArrangedSubview:self.coinImageView];
[self.stackView addArrangedSubview:self.priceLabel];
if (@available(iOS 11.0, *)) {
[self.stackView setCustomSpacing:8 afterView:self.titleLabel];
[self.stackView setCustomSpacing:6 afterView:self.coinImageView];
}
2025-11-10 15:29:21 +08:00
[self.coinImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(18);
}];
//
self.titleText = @"Download";
self.priceText = @"20";
UIImage *img = [UIImage systemImageNamed:@"circle.fill"];
self.iconImage = img; //
self.coinImageView.tintColor = [UIColor colorWithRed:1.0 green:0.85 blue:0.2 alpha:1.0];
2025-12-11 16:39:22 +08:00
self.showsPrice = YES;
2025-11-10 15:29:21 +08:00
//
[self addTarget:self action:@selector(handleTap) forControlEvents:UIControlEventTouchUpInside];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
//
self.layer.cornerRadius = CGRectGetHeight(self.bounds) * 0.5;
}
#pragma mark - Public
- (void)configWithTitle:(nullable NSString *)title price:(nullable NSString *)price icon:(nullable UIImage *)icon {
if (title.length) self.titleText = title;
if (price.length) self.priceText = price;
if (icon) self.iconImage = icon;
}
#pragma mark - Actions
- (void)onTouchDown { self.alpha = 0.85; }
- (void)onTouchUp { self.alpha = 1.0; }
- (void)handleTap {
if (self.tapHandler) { self.tapHandler(); }
}
#pragma mark - Setters
- (void)setTitleText:(NSString *)titleText {
_titleText = [titleText copy];
self.titleLabel.text = _titleText;
}
- (void)setPriceText:(NSString *)priceText {
_priceText = [priceText copy];
2025-12-11 16:39:22 +08:00
if (self.showsPrice) {
self.priceLabel.text = _priceText;
}
2025-11-10 15:29:21 +08:00
}
- (void)setIconImage:(UIImage *)iconImage {
_iconImage = iconImage;
self.coinImageView.image = _iconImage;
}
2025-12-11 16:39:22 +08:00
- (void)setShowsPrice:(BOOL)showsPrice {
if (_showsPrice == showsPrice) { return; }
_showsPrice = showsPrice;
self.coinImageView.hidden = !_showsPrice;
self.priceLabel.hidden = !_showsPrice;
self.priceLabel.text = _showsPrice ? self.priceText : @"";
if (@available(iOS 11.0, *)) {
[self.stackView setCustomSpacing:_showsPrice ? 8 : 0 afterView:self.titleLabel];
}
}
2025-11-10 15:29:21 +08:00
#pragma mark - Lazy
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
2025-11-25 15:36:16 +08:00
_titleLabel.font = [KBFont medium:16];
2025-11-10 15:29:21 +08:00
_titleLabel.textColor = [UIColor whiteColor];
_titleLabel.textAlignment = NSTextAlignmentCenter;
}
return _titleLabel;
}
- (UIView *)contentView {
if (!_contentView) {
_contentView = [[UIView alloc] init];
_contentView.backgroundColor = [UIColor clearColor];
2025-12-11 16:45:39 +08:00
_contentView.userInteractionEnabled = NO; // UIControl
2025-11-10 15:29:21 +08:00
//
[_contentView setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[_contentView setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
}
return _contentView;
}
2025-12-11 16:39:22 +08:00
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.alignment = UIStackViewAlignmentCenter;
_stackView.spacing = 6;
2025-12-11 16:45:39 +08:00
_stackView.userInteractionEnabled = NO; // UIControl
2025-12-11 16:39:22 +08:00
}
return _stackView;
}
2025-11-10 15:29:21 +08:00
- (UIImageView *)coinImageView {
if (!_coinImageView) {
_coinImageView = [[UIImageView alloc] init];
_coinImageView.contentMode = UIViewContentModeScaleAspectFit;
_coinImageView.clipsToBounds = YES;
}
return _coinImageView;
}
- (UILabel *)priceLabel {
if (!_priceLabel) {
_priceLabel = [[UILabel alloc] init];
2025-11-25 15:36:16 +08:00
_priceLabel.font = [KBFont medium:16];
2025-11-10 15:29:21 +08:00
_priceLabel.textColor = [UIColor whiteColor];
_priceLabel.textAlignment = NSTextAlignmentCenter;
}
return _priceLabel;
}
@end