This commit is contained in:
2025-11-07 19:33:54 +08:00
parent c3acc11f6a
commit 450798c8bd
2 changed files with 71 additions and 93 deletions

View File

@@ -9,9 +9,7 @@
///
@property (nonatomic, strong) UIView *avatarCircleView;
///
@property (nonatomic, strong) UIView *cardView;
/// 1/2/3
@property (nonatomic, strong) UILabel *medalLabel;
@property (nonatomic, strong) UIImageView *cardImageView;
///
@property (nonatomic, strong) UILabel *titleLabel;
///
@@ -32,11 +30,10 @@
- (void)setupUI {
//
[self addSubview:self.cardView];
[self addSubview:self.cardImageView];
//
[self addSubview:self.avatarCircleView];
[self.cardView addSubview:self.medalLabel];
[self.cardView addSubview:self.titleLabel];
[self.cardImageView addSubview:self.titleLabel];
//
[self addSubview:self.plusButton];
@@ -47,25 +44,21 @@
make.width.height.mas_equalTo(68);
}];
[self.cardView mas_makeConstraints:^(MASConstraintMaker *make) {
[self.cardImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.avatarCircleView.mas_bottom).offset(-34); //
make.left.right.equalTo(self);
make.height.mas_equalTo(146);
make.height.mas_equalTo(148);
}];
[self.medalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.cardView).offset(34 + 15);
make.centerX.equalTo(self.cardView);
make.width.height.mas_equalTo(28);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.cardView);
make.top.equalTo(self.medalLabel.mas_bottom).offset(20);
make.centerX.equalTo(self.cardImageView);
make.top.equalTo(self.cardImageView).offset(84);
}];
[self.plusButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.cardView.mas_bottom).offset(12);
make.top.equalTo(self.cardImageView.mas_bottom).offset(12);
make.centerX.equalTo(self);
make.width.mas_equalTo(52);
make.height.mas_equalTo(28);
@@ -75,16 +68,29 @@
- (void)renderWithTitle:(NSString *)title rank:(NSInteger)rank {
self.titleLabel.text = title.length ? title : @"";
self.medalLabel.text = [NSString stringWithFormat:@"%ld", (long)rank];
//
UIColor *theme;
UIImage *image;
switch (rank) {
case 1: theme = [UIColor colorWithRed:1.00 green:0.86 blue:0.43 alpha:1.0]; break; //
case 2: theme = [UIColor colorWithRed:0.68 green:0.80 blue:1.00 alpha:1.0]; break; //
default: theme = [UIColor colorWithRed:1.00 green:0.78 blue:0.63 alpha:1.0]; break; //
case 1:
{
theme = [UIColor colorWithRed:1.00 green:0.86 blue:0.43 alpha:1.0];
image = [UIImage imageNamed:@"home_rank_1"];
}
break; //
case 2: {
theme = [UIColor colorWithRed:0.68 green:0.80 blue:1.00 alpha:1.0];
image = [UIImage imageNamed:@"home_rank_2"];
}
break; //
default: {
theme = [UIColor colorWithRed:1.00 green:0.78 blue:0.63 alpha:1.0];
image = [UIImage imageNamed:@"home_rank_3"];
} break; //
}
self.cardView.backgroundColor = theme;
self.cardImageView.image = image;
self.plusButton.backgroundColor = [theme colorWithAlphaComponent:0.3];
//
@@ -105,28 +111,13 @@
return _avatarCircleView;
}
- (UIView *)cardView {
if (!_cardView) {
_cardView = [[UIView alloc] init];
_cardView.layer.cornerRadius = 14.0;
_cardView.layer.masksToBounds = YES;
_cardView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
- (UIImageView *)cardImageView {
if (!_cardImageView) {
_cardImageView = [[UIImageView alloc] init];
}
return _cardView;
return _cardImageView;
}
- (UILabel *)medalLabel {
if (!_medalLabel) {
_medalLabel = [[UILabel alloc] init];
_medalLabel.textAlignment = NSTextAlignmentCenter;
_medalLabel.font = [UIFont boldSystemFontOfSize:15];
_medalLabel.textColor = [UIColor whiteColor];
_medalLabel.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.7];
_medalLabel.layer.cornerRadius = 14;
_medalLabel.layer.masksToBounds = YES;
}
return _medalLabel;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
@@ -163,7 +154,7 @@
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor colorWithWhite:0.98 alpha:1];
self.backgroundColor = [UIColor whiteColor];
[self setupUI];
}
return self;