135 lines
4.4 KiB
Mathematica
135 lines
4.4 KiB
Mathematica
|
|
//
|
|||
|
|
// 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
|
|||
|
|
|