添加底部view

This commit is contained in:
2025-11-10 15:29:21 +08:00
parent fac5e7657c
commit 97316c7989
6 changed files with 243 additions and 6 deletions

View File

@@ -0,0 +1,153 @@
//
// KBSkinBottomActionView.m
// keyBoard
//
//
#import "KBSkinBottomActionView.h"
@interface KBSkinBottomActionView ()
@property (nonatomic, strong) UIView *contentView; // 使
@property (nonatomic, strong) UILabel *titleLabel; //
@property (nonatomic, strong) UIImageView *coinImageView; //
@property (nonatomic, strong) UILabel *priceLabel; //
@end
@implementation KBSkinBottomActionView
+ (CGFloat)preferredHeight { return 45.0; }
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor colorWithHex:0x02BEAC];
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
[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.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";
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];
//
[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];
self.priceLabel.text = _priceText;
}
- (void)setIconImage:(UIImage *)iconImage {
_iconImage = iconImage;
self.coinImageView.image = _iconImage;
}
#pragma mark - Lazy
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold];
_titleLabel.textColor = [UIColor whiteColor];
_titleLabel.textAlignment = NSTextAlignmentCenter;
}
return _titleLabel;
}
- (UIView *)contentView {
if (!_contentView) {
_contentView = [[UIView alloc] init];
_contentView.backgroundColor = [UIColor clearColor];
//
[_contentView setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[_contentView setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
}
return _contentView;
}
- (UIImageView *)coinImageView {
if (!_coinImageView) {
_coinImageView = [[UIImageView alloc] init];
_coinImageView.contentMode = UIViewContentModeScaleAspectFit;
_coinImageView.clipsToBounds = YES;
}
return _coinImageView;
}
- (UILabel *)priceLabel {
if (!_priceLabel) {
_priceLabel = [[UILabel alloc] init];
_priceLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold];
_priceLabel.textColor = [UIColor whiteColor];
_priceLabel.textAlignment = NSTextAlignmentCenter;
}
return _priceLabel;
}
@end