1
This commit is contained in:
@@ -6,16 +6,16 @@
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "KBCharacter.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/// 用于 HomeHot 顶部展示前三名的视图
|
||||
@interface KBTopThreeView : UIView
|
||||
|
||||
/// 配置三项内容(数组元素可传 @{ @"title":NSString, @"rank":@(1/2/3) })
|
||||
- (void)configWithItems:(NSArray<NSDictionary *> *)items;
|
||||
/// 使用前三名角色模型进行配置(数组元素为 KBCharacter*,最多取前三个)
|
||||
- (void)configWithCharacters:(NSArray<KBCharacter *> *)characters;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user