This commit is contained in:
2025-12-11 16:39:22 +08:00
parent e4442afe72
commit 7f90240731
6 changed files with 207 additions and 32 deletions

View File

@@ -7,10 +7,11 @@
#import "KBSkinBottomActionView.h"
@interface KBSkinBottomActionView ()
@property (nonatomic, strong) UIView *contentView; // 使
@property (nonatomic, strong) UILabel *titleLabel; //
@property (nonatomic, strong) UIView *contentView; // 使
@property (nonatomic, strong) UIStackView *stackView; // Title/Icon/Price
@property (nonatomic, strong) UILabel *titleLabel; //
@property (nonatomic, strong) UIImageView *coinImageView; //
@property (nonatomic, strong) UILabel *priceLabel; //
@property (nonatomic, strong) UILabel *priceLabel; //
@end
@implementation KBSkinBottomActionView
@@ -37,24 +38,20 @@
}];
// Title - Icon - Price
[self.contentView addSubview:self.titleLabel];
[self.contentView addSubview:self.coinImageView];
[self.contentView addSubview:self.priceLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView);
make.centerY.equalTo(self.contentView);
[self.contentView addSubview:self.stackView];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.contentView);
}];
[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];
}
[self.coinImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.titleLabel.mas_right).offset(8);
make.centerY.equalTo(self.contentView);
make.width.height.mas_equalTo(18);
}];
[self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.coinImageView.mas_right).offset(6);
make.right.equalTo(self.contentView);
make.centerY.equalTo(self.contentView);
}];
//
self.titleText = @"Download";
@@ -62,6 +59,7 @@
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];
self.showsPrice = YES;
//
[self addTarget:self action:@selector(handleTap) forControlEvents:UIControlEventTouchUpInside];
}
@@ -100,7 +98,9 @@
- (void)setPriceText:(NSString *)priceText {
_priceText = [priceText copy];
self.priceLabel.text = _priceText;
if (self.showsPrice) {
self.priceLabel.text = _priceText;
}
}
- (void)setIconImage:(UIImage *)iconImage {
@@ -108,6 +108,17 @@
self.coinImageView.image = _iconImage;
}
- (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];
}
}
#pragma mark - Lazy
- (UILabel *)titleLabel {
@@ -131,6 +142,16 @@
return _contentView;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.alignment = UIStackViewAlignmentCenter;
_stackView.spacing = 6;
}
return _stackView;
}
- (UIImageView *)coinImageView {
if (!_coinImageView) {
_coinImageView = [[UIImageView alloc] init];