This commit is contained in:
2025-11-06 14:59:00 +08:00
parent 15fc9621cd
commit a1db745b6c
9 changed files with 517 additions and 24 deletions

View File

@@ -0,0 +1,134 @@
//
// HomeHotCell.m
// keyBoard
//
#import "HomeHotCell.h"
@interface HomeHotCell()
//
@property (nonatomic, strong) UILabel *rankLabel;
//
@property (nonatomic, strong) UIView *avatarView;
//
@property (nonatomic, strong) UILabel *titleLabel;
//
@property (nonatomic, strong) UILabel *subLabel;
//
@property (nonatomic, strong) UIButton *actionButton;
@end
@implementation HomeHotCell
- (void)setupUI {
[super setupUI];
//
[self.contentView addSubview:self.rankLabel];
[self.contentView addSubview:self.avatarView];
[self.contentView addSubview:self.titleLabel];
[self.contentView addSubview:self.subLabel];
[self.contentView addSubview:self.actionButton];
// 使 Masonry
[self.rankLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(16);
make.centerY.equalTo(self.contentView);
}];
[self.avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.rankLabel.mas_right).offset(12);
make.centerY.equalTo(self.contentView);
make.width.height.mas_equalTo(52);
}];
[self.actionButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.contentView);
make.right.equalTo(self.contentView).offset(-16);
make.width.mas_equalTo(64);
make.height.mas_equalTo(36);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.avatarView.mas_right).offset(12);
make.top.equalTo(self.avatarView.mas_top).offset(-2);
make.right.lessThanOrEqualTo(self.actionButton.mas_left).offset(-12);
}];
[self.subLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.titleLabel);
make.right.equalTo(self.titleLabel);
make.bottom.equalTo(self.avatarView.mas_bottom).offset(2);
}];
}
- (void)configWithRank:(NSInteger)rank title:(NSString *)title subtitle:(NSString *)sub joined:(BOOL)joined {
self.rankLabel.text = [NSString stringWithFormat:@"%ld", (long)rank];
self.titleLabel.text = title ?: @"";
self.subLabel.text = sub ?: @"";
if (joined) {
//
[self.actionButton setTitle:@"✓" forState:UIControlStateNormal];
[self.actionButton setTitleColor:[UIColor colorWithWhite:0.45 alpha:1] forState:UIControlStateNormal];
self.actionButton.backgroundColor = [UIColor colorWithWhite:0.92 alpha:1];
} else {
// 绿
[self.actionButton setTitle:@"+" forState:UIControlStateNormal];
[self.actionButton setTitleColor:[UIColor colorWithRed:0.20 green:0.65 blue:0.50 alpha:1.0] forState:UIControlStateNormal];
self.actionButton.backgroundColor = [UIColor colorWithRed:0.88 green:0.97 blue:0.93 alpha:1.0];
}
}
#pragma mark - Lazy
- (UILabel *)rankLabel {
if (!_rankLabel) {
_rankLabel = [[UILabel alloc] init];
_rankLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
_rankLabel.textColor = [UIColor colorWithRed:0.15 green:0.55 blue:0.45 alpha:1.0];
}
return _rankLabel;
}
- (UIView *)avatarView {
if (!_avatarView) {
_avatarView = [[UIView alloc] init];
_avatarView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
_avatarView.layer.cornerRadius = 26;
_avatarView.layer.masksToBounds = YES;
}
return _avatarView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
_titleLabel.textColor = [UIColor colorWithWhite:0.1 alpha:1];
}
return _titleLabel;
}
- (UILabel *)subLabel {
if (!_subLabel) {
_subLabel = [[UILabel alloc] init];
_subLabel.font = [UIFont systemFontOfSize:13];
_subLabel.textColor = [UIColor colorWithWhite:0.5 alpha:1];
_subLabel.numberOfLines = 1;
}
return _subLabel;
}
- (UIButton *)actionButton {
if (!_actionButton) {
_actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
_actionButton.layer.cornerRadius = 18;
_actionButton.layer.masksToBounds = YES;
_actionButton.titleLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightBold];
}
return _actionButton;
}
@end