This commit is contained in:
2025-11-10 19:51:23 +08:00
parent 1dc9560a1f
commit 3eb3a86376
17 changed files with 125 additions and 21 deletions

View File

@@ -16,7 +16,12 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong, readonly) UILabel *nameLabel; // 名称/提示
@property (nonatomic, strong, readonly) UIView *cardLeft; // 左卡片
@property (nonatomic, strong, readonly) UIView *cardRight; // 右卡片
/// 点击事件回调(由外部控制器设置)。
@property (nonatomic, copy) void (^onKeyboardTapped)(void);
@property (nonatomic, copy) void (^onAvatarTapped)(void);
@property (nonatomic, copy) void (^onLeftCardTapped)(void);
@property (nonatomic, copy) void (^onRightCardTapped)(void);
@end
NS_ASSUME_NONNULL_END

View File

@@ -14,6 +14,7 @@
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIImageView *cardLeft;
@property (nonatomic, strong) UIImageView *cardRight;
@property (nonatomic, strong) UIImageView *avatarEditIcon; //
@end
@implementation KBMyHeaderView
@@ -25,6 +26,7 @@
[self addSubview:self.titleLabel];
[self addSubview:self.keyboardBtn];
[self addSubview:self.avatarView];
[self addSubview:self.avatarEditIcon]; //
[self addSubview:self.nameLabel];
[self addSubview:self.cardLeft];
[self addSubview:self.cardRight];
@@ -38,13 +40,18 @@
make.centerY.equalTo(self.titleLabel);
make.right.equalTo(self).offset(-20);
make.height.mas_equalTo(34);
make.width.mas_greaterThanOrEqualTo(126);
make.width.mas_greaterThanOrEqualTo(115);
}];
[self.avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(26);
make.bottom.equalTo(self.cardLeft.mas_top).offset(-23);
make.width.height.mas_equalTo(70);
}];
[self.avatarEditIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(18);
make.right.equalTo(self.avatarView.mas_right);
make.bottom.equalTo(self.avatarView.mas_bottom);
}];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.avatarView);
make.left.equalTo(self.avatarView.mas_right).offset(12);
@@ -106,12 +113,25 @@
- (UIButton *)keyboardBtn {
if (!_keyboardBtn) {
_keyboardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_keyboardBtn setTitle:@" My Keyboard " forState:UIControlStateNormal];
[_keyboardBtn setTitle:@"My Keyboard" forState:UIControlStateNormal];
_keyboardBtn.titleLabel.font = [UIFont systemFontOfSize:10 weight:UIFontWeightSemibold];
[_keyboardBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_keyboardBtn.backgroundColor = [UIColor colorWithHex:KBColor];
_keyboardBtn.backgroundColor = [UIColor colorWithHex:KBColorValue];
_keyboardBtn.layer.cornerRadius = 17;
_keyboardBtn.layer.masksToBounds = YES;
// + 6
UIImage *kbImg = [UIImage imageNamed:@"my_kb_icon"];
if (kbImg) {
[_keyboardBtn setImage:kbImg forState:UIControlStateNormal];
_keyboardBtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
CGFloat spacing = 6.0;
_keyboardBtn.contentEdgeInsets = UIEdgeInsetsMake(0, spacing, 0, spacing);
_keyboardBtn.titleEdgeInsets = UIEdgeInsetsMake(0, spacing, 0, -spacing);
}
//
[_keyboardBtn addTarget:self action:@selector(onKeyboardTap) forControlEvents:UIControlEventTouchUpInside];
}
return _keyboardBtn;
}
@@ -121,6 +141,9 @@
_avatarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lufei.jpg"]];
_avatarView.contentMode = UIViewContentModeScaleAspectFill;
_avatarView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1.0];
_avatarView.userInteractionEnabled = YES; //
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onAvatarTap)];
[_avatarView addGestureRecognizer:tap];
}
return _avatarView;
}
@@ -135,8 +158,43 @@
return _nameLabel;
}
- (UIImageView *)cardLeft { if (!_cardLeft) { _cardLeft = [UIImageView new]; _cardLeft.contentMode = UIViewContentModeScaleAspectFit; _cardLeft.image = [UIImage imageNamed:@"my_member_icon"];} return _cardLeft; }
- (UIImageView *)cardRight { if (!_cardRight) { _cardRight = [UIImageView new];_cardRight.contentMode = UIViewContentModeScaleAspectFit; _cardRight.image = [UIImage imageNamed:@"my_recharge_icon"];} return _cardRight; }
- (UIImageView *)cardLeft {
if (!_cardLeft) {
_cardLeft = [UIImageView new];
_cardLeft.contentMode = UIViewContentModeScaleAspectFit;
_cardLeft.image = [UIImage imageNamed:@"my_member_icon"];
_cardLeft.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onLeftCardTap)];
[_cardLeft addGestureRecognizer:tap];
}
return _cardLeft;
}
- (UIImageView *)cardRight {
if (!_cardRight) {
_cardRight = [UIImageView new];
_cardRight.contentMode = UIViewContentModeScaleAspectFit;
_cardRight.image = [UIImage imageNamed:@"my_recharge_icon"];
_cardRight.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onRightCardTap)];
[_cardRight addGestureRecognizer:tap];
}
return _cardRight;
}
- (UIImageView *)avatarEditIcon {
if (!_avatarEditIcon) {
_avatarEditIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"my_head_edite"]];
_avatarEditIcon.contentMode = UIViewContentModeScaleAspectFit;
_avatarEditIcon.userInteractionEnabled = NO; //
}
return _avatarEditIcon;
}
#pragma mark - Actions
- (void)onKeyboardTap { if (self.onKeyboardTapped) { self.onKeyboardTapped(); } }
- (void)onAvatarTap { if (self.onAvatarTapped) { self.onAvatarTapped(); } }
- (void)onLeftCardTap { if (self.onLeftCardTapped) { self.onLeftCardTapped(); } }
- (void)onRightCardTap { if (self.onRightCardTapped) { self.onRightCardTapped(); } }
@end

View File

@@ -59,8 +59,8 @@
}];
[self.arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.container);
make.right.equalTo(self.container).offset(-12);
make.width.mas_equalTo(8);
make.right.equalTo(self.container).offset(-16);
make.width.mas_equalTo(9);
make.height.mas_equalTo(14);
}];
[self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -109,11 +109,7 @@
if (!_arrowView) {
_arrowView = [[UIImageView alloc] init];
_arrowView.contentMode = UIViewContentModeScaleAspectFit;
_arrowView.tintColor = [UIColor colorWithHex:0xC0C0C0];
// iOS13+ 使
if (@available(iOS 13.0, *)) {
_arrowView.image = [UIImage systemImageNamed:@"chevron.right"];
}
_arrowView.image = [UIImage imageNamed:@"black_right_arrow"];
}
return _arrowView;
}

View File

@@ -19,7 +19,7 @@
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor colorWithHex:KBColor];
self.backgroundColor = [UIColor colorWithHex:KBColorValue];
self.layer.masksToBounds = YES; //
//

View File

@@ -65,7 +65,7 @@
- (UILabel *)rightLabel {
if (!_rightLabel) {
_rightLabel = [UILabel new];
_rightLabel.textColor = [UIColor colorWithHex:KBColor];
_rightLabel.textColor = [UIColor colorWithHex:KBColorValue];
_rightLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
_rightLabel.textAlignment = NSTextAlignmentRight;
_rightLabel.text = @"Download: 1 Million";

View File

@@ -61,7 +61,7 @@
- (void)applySelected:(BOOL)selected {
self.selectedState = selected;
UIColor *fill = selected ? [UIColor colorWithHex:KBColor] : [UIColor colorWithWhite:0 alpha:0.51];
UIColor *fill = selected ? [UIColor colorWithHex:KBColorValue] : [UIColor colorWithWhite:0 alpha:0.51];
_circleLayer.fillColor = fill.CGColor; // #02BEAC
_checkLayer.hidden = !selected; //
}