1
This commit is contained in:
@@ -22,6 +22,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
/// 图标(可选),例如金币图
|
||||
@property (nonatomic, strong, nullable) UIImage *iconImage;
|
||||
|
||||
/// 是否展示价格区域(隐藏后仅显示标题)
|
||||
@property (nonatomic, assign) BOOL showsPrice;
|
||||
|
||||
/// 点击回调(也可直接 addTarget 使用)
|
||||
@property (nonatomic, copy, nullable) void (^tapHandler)(void);
|
||||
|
||||
@@ -34,4 +37,3 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user