Files
keyboard/keyBoard/Class/Home/V/HomeRankCardCell.m

207 lines
7.1 KiB
Mathematica
Raw Normal View History

2025-11-06 19:51:50 +08:00
//
// HomeRankCardCell.m
// keyBoard
//
// Created by Codex on 2025/11/06.
//
@import UIKit;
#import "HomeRankCardCell.h"
2025-11-06 21:38:58 +08:00
#import "UIView+KBShadow.h"
2025-12-03 19:38:55 +08:00
#import "UIImageView+KBWebImage.h"
2025-11-06 19:51:50 +08:00
@interface HomeRankCardCell ()
2025-12-03 19:19:20 +08:00
@property (nonatomic, strong) UIView *shadowView; //
2025-12-03 19:38:55 +08:00
@property (nonatomic, strong) UIView *cardView; //
@property (nonatomic, strong) UIImageView *averImageView; //
2025-11-06 19:51:50 +08:00
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *descLabel;
@property (nonatomic, strong) UILabel *peopleLabel;
2025-12-03 19:19:20 +08:00
@property (nonatomic, strong) UIButton *actionBtn; // /
2025-11-06 19:51:50 +08:00
@property (nonatomic, assign) BOOL added;
@end
@implementation HomeRankCardCell
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.contentView.backgroundColor = UIColor.clearColor;
[self setupUI];
[self setupConstraints];
}
return self;
}
- (void)setupUI {
// 使访
[self.contentView addSubview:self.shadowView];
[self.shadowView addSubview:self.cardView];
2025-12-03 19:38:55 +08:00
[self.contentView addSubview:self.averImageView];
2025-11-06 19:51:50 +08:00
[self.cardView addSubview:self.titleLabel];
[self.cardView addSubview:self.descLabel];
[self.cardView addSubview:self.peopleLabel];
[self.cardView addSubview:self.actionBtn];
2025-11-06 21:38:58 +08:00
// 8pt
[self.shadowView kb_setCardShadowWithCornerRadius:18.0 insets:UIEdgeInsetsMake(0, 8, 0, 8)];
2025-11-06 19:51:50 +08:00
}
- (void)setupConstraints {
// Masonry
[self.shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.equalTo(self.contentView);
2025-11-07 21:57:42 +08:00
make.top.equalTo(self.contentView.mas_top).offset(68 * 0.5); //
2025-11-06 19:51:50 +08:00
}];
[self.cardView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.shadowView).insets(UIEdgeInsetsMake(0, 8, 0, 8));
}];
2025-12-03 19:38:55 +08:00
[self.averImageView mas_makeConstraints:^(MASConstraintMaker *make) {
2025-11-06 19:51:50 +08:00
make.centerX.equalTo(self.cardView);
make.centerY.equalTo(self.shadowView.mas_top);
make.width.height.mas_equalTo(68);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
2025-12-03 19:38:55 +08:00
make.top.equalTo(self.averImageView.mas_bottom).offset(13);
2025-11-06 19:51:50 +08:00
make.left.equalTo(self.cardView.mas_left).offset(18);
make.right.equalTo(self.cardView.mas_right).offset(-18);
2025-11-07 21:57:42 +08:00
make.height.mas_equalTo(23);
2025-11-06 19:51:50 +08:00
}];
[self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.titleLabel.mas_bottom).offset(12);
make.left.equalTo(self.cardView.mas_left).offset(18);
make.right.equalTo(self.cardView.mas_right).offset(-18);
}];
[self.peopleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
2025-11-07 21:57:42 +08:00
make.top.equalTo(self.descLabel.mas_bottom).offset(8);
2025-11-06 19:51:50 +08:00
make.left.equalTo(self.cardView.mas_left).offset(18);
make.right.equalTo(self.cardView.mas_right).offset(-18);
}];
[self.actionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.cardView.mas_left).offset(18);
make.right.equalTo(self.cardView.mas_right).offset(-18);
2025-11-07 21:57:42 +08:00
make.bottom.equalTo(self.cardView.mas_bottom).offset(-12);
make.height.mas_equalTo(32);
2025-11-06 19:51:50 +08:00
}];
}
- (void)layoutSubviews {
[super layoutSubviews];
2025-11-06 21:38:58 +08:00
//
[self.shadowView kb_updateShadowPath];
2025-11-06 19:51:50 +08:00
2025-12-03 19:38:55 +08:00
self.averImageView.layer.cornerRadius = 34;
2025-12-03 19:43:45 +08:00
self.averImageView.layer.masksToBounds = true;
2025-11-06 19:51:50 +08:00
}
- (void)prepareForReuse {
[super prepareForReuse];
self.onTapAction = nil;
}
- (void)tapAction {
if (self.onTapAction) self.onTapAction();
}
2025-12-03 19:38:55 +08:00
- (void)setCharacter:(KBCharacter *)character {
_character = character;
BOOL added = character.added;
2025-11-06 19:51:50 +08:00
self.added = added;
2025-12-03 19:38:55 +08:00
self.titleLabel.text = character.characterName;
self.descLabel.text = character.characterBackground;
self.peopleLabel.text = character.download;
[self.averImageView kb_setAvatarURL:character.avatarUrl placeholder:KBAvatarPlaceholderImage];
2025-11-06 19:51:50 +08:00
if (added) {
//
self.actionBtn.backgroundColor = [UIColor colorWithWhite:0.93 alpha:1.0];
[self.actionBtn setTitle:@"✓" forState:UIControlStateNormal];
[self.actionBtn setTitleColor:[UIColor colorWithWhite:0.55 alpha:1.0] forState:UIControlStateNormal];
} else {
//
self.actionBtn.backgroundColor = [UIColor blackColor];
[self.actionBtn setTitle:@"+" forState:UIControlStateNormal];
[self.actionBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
2025-12-04 19:12:34 +08:00
//
self.actionBtn.enabled = !added;
2025-11-06 19:51:50 +08:00
}
#pragma mark - Lazy UI
- (UIView *)shadowView {
if (!_shadowView) {
_shadowView = [UIView new];
_shadowView.backgroundColor = UIColor.clearColor;
}
return _shadowView;
}
2025-12-03 19:38:55 +08:00
- (UIView *)cardView {
2025-11-06 19:51:50 +08:00
if (!_cardView) {
2025-12-03 19:38:55 +08:00
_cardView = [[UIView alloc] init];
2025-11-06 19:51:50 +08:00
_cardView.backgroundColor = UIColor.whiteColor;
}
return _cardView;
}
2025-12-03 19:38:55 +08:00
- (UIImageView *)averImageView {
if (!_averImageView) {
_averImageView = [UIImageView new];
_averImageView.backgroundColor = UIColor.whiteColor;
_averImageView.layer.borderColor = [UIColor colorWithRed:0.78 green:0.90 blue:0.20 alpha:1.0].CGColor;
_averImageView.layer.borderWidth = 3.0;
2025-11-06 19:51:50 +08:00
}
2025-12-03 19:38:55 +08:00
return _averImageView;
2025-11-06 19:51:50 +08:00
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [UILabel new];
2025-11-07 21:57:42 +08:00
_titleLabel.textColor = [UIColor colorWithHex:0x1B1F1A];
2025-11-25 15:36:16 +08:00
_titleLabel.font = [KBFont medium:16];
2025-11-06 19:51:50 +08:00
_titleLabel.textAlignment = NSTextAlignmentCenter;
}
return _titleLabel;
}
- (UILabel *)descLabel {
if (!_descLabel) {
_descLabel = [UILabel new];
2025-11-07 21:57:42 +08:00
_descLabel.textColor = [UIColor colorWithHex:0x9A9A9A];
2025-11-25 15:36:16 +08:00
_descLabel.font = [KBFont regular:12];
2025-11-06 19:51:50 +08:00
_descLabel.textAlignment = NSTextAlignmentCenter;
_descLabel.numberOfLines = 2;
}
return _descLabel;
}
- (UILabel *)peopleLabel {
if (!_peopleLabel) {
_peopleLabel = [UILabel new];
2025-11-10 19:51:23 +08:00
_peopleLabel.textColor = [UIColor colorWithHex:KBColorValue];
2025-11-25 15:36:16 +08:00
_peopleLabel.font = [KBFont regular:10];
2025-11-06 19:51:50 +08:00
_peopleLabel.textAlignment = NSTextAlignmentCenter;
_peopleLabel.numberOfLines = 2;
}
return _peopleLabel;
}
- (UIButton *)actionBtn {
if (!_actionBtn) {
_actionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
2025-11-07 21:57:42 +08:00
_actionBtn.layer.cornerRadius = 4.0;
2025-11-06 19:51:50 +08:00
_actionBtn.layer.masksToBounds = YES;
[_actionBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
2025-11-07 21:57:42 +08:00
_actionBtn.titleLabel.font = [UIFont systemFontOfSize:22 weight:UIFontWeightSemibold];
2025-11-06 19:51:50 +08:00
[_actionBtn addTarget:self action:@selector(tapAction) forControlEvents:UIControlEventTouchUpInside];
}
return _actionBtn;
}
@end