This commit is contained in:
2025-12-03 20:02:37 +08:00
parent f026b9f9fd
commit eca168957d
3 changed files with 33 additions and 30 deletions

View File

@@ -4,17 +4,18 @@
//
#import "KBTopThreeView.h"
#import "UIImageView+KBWebImage.h"
@interface KBTopThreeCardView : UIView
///
///
@property (nonatomic, strong) UIImageView *avatarCircleView;
///
@property (nonatomic, strong) UIImageView *cardImageView;
///
@property (nonatomic, strong) UILabel *titleLabel;
///
- (void)renderWithTitle:(NSString *)title rank:(NSInteger)rank;
/// 使
- (void)renderWithCharacter:(KBCharacter *)character rank:(NSInteger)rank;
@end
@implementation KBTopThreeCardView
@@ -55,7 +56,8 @@
}
- (void)renderWithTitle:(NSString *)title rank:(NSInteger)rank {
- (void)renderWithCharacter:(KBCharacter *)character rank:(NSInteger)rank {
NSString *title = character.characterName ?: @"";
self.titleLabel.text = title.length ? title : @"";
//
@@ -80,7 +82,9 @@
} break; //
}
self.cardImageView.image = image;
// KBTopThreeView
//
[self.avatarCircleView kb_setAvatarURL:character.avatarUrl placeholder:KBPlaceholderImage];
//
self.avatarCircleView.layer.borderColor = [UIColor colorWithRed:0.83 green:0.95 blue:0.27 alpha:1.0].CGColor;
@@ -94,6 +98,7 @@
_avatarCircleView.backgroundColor = [UIColor whiteColor];
_avatarCircleView.layer.cornerRadius = 34;
_avatarCircleView.layer.borderWidth = 2.0;
_avatarCircleView.layer.masksToBounds = true;
}
return _avatarCircleView;
}
@@ -197,19 +202,22 @@
}];
}
- (void)configWithItems:(NSArray<NSDictionary *> *)items {
// items rank 1 2 3
NSString *t1 = @"", *t2 = @"", *t3 = @"";
for (NSDictionary *d in items) {
NSInteger r = [d[@"rank"] integerValue];
NSString *title = d[@"title"] ?: @"";
if (r == 1) t1 = title;
else if (r == 2) t2 = title;
else if (r == 3) t3 = title;
- (void)configWithCharacters:(NSArray<KBCharacter *> *)characters {
if (characters.count == 0) {
//
[self.centerCard renderWithCharacter:[KBCharacter new] rank:1];
[self.leftCard renderWithCharacter:[KBCharacter new] rank:2];
[self.rightCard renderWithCharacter:[KBCharacter new] rank:3];
return;
}
[self.centerCard renderWithTitle:t1 rank:1];
[self.leftCard renderWithTitle:t2 rank:2];
[self.rightCard renderWithTitle:t3 rank:3];
KBCharacter *first = characters.count > 0 ? characters[0] : nil;
KBCharacter *second = characters.count > 1 ? characters[1] : nil;
KBCharacter *third = characters.count > 2 ? characters[2] : nil;
if (first) [self.centerCard renderWithCharacter:first rank:1];
if (second) [self.leftCard renderWithCharacter:second rank:2];
if (third) [self.rightCard renderWithCharacter:third rank:3];
}
#pragma mark - Lazy