1
This commit is contained in:
@@ -6,16 +6,16 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
#import "KBCharacter.h"
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
/// 用于 HomeHot 顶部展示前三名的视图
|
/// 用于 HomeHot 顶部展示前三名的视图
|
||||||
@interface KBTopThreeView : UIView
|
@interface KBTopThreeView : UIView
|
||||||
|
|
||||||
/// 配置三项内容(数组元素可传 @{ @"title":NSString, @"rank":@(1/2/3) })
|
/// 使用前三名角色模型进行配置(数组元素为 KBCharacter*,最多取前三个)
|
||||||
- (void)configWithItems:(NSArray<NSDictionary *> *)items;
|
- (void)configWithCharacters:(NSArray<KBCharacter *> *)characters;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
||||||
|
|||||||
@@ -4,17 +4,18 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "KBTopThreeView.h"
|
#import "KBTopThreeView.h"
|
||||||
|
#import "UIImageView+KBWebImage.h"
|
||||||
|
|
||||||
@interface KBTopThreeCardView : UIView
|
@interface KBTopThreeCardView : UIView
|
||||||
/// 头像占位(圆形描边)
|
/// 头像视图(圆形描边)
|
||||||
@property (nonatomic, strong) UIImageView *avatarCircleView;
|
@property (nonatomic, strong) UIImageView *avatarCircleView;
|
||||||
/// 彩条卡片背景
|
/// 彩条卡片背景
|
||||||
@property (nonatomic, strong) UIImageView *cardImageView;
|
@property (nonatomic, strong) UIImageView *cardImageView;
|
||||||
/// 标题
|
/// 标题
|
||||||
@property (nonatomic, strong) UILabel *titleLabel;
|
@property (nonatomic, strong) UILabel *titleLabel;
|
||||||
|
|
||||||
/// 渲染
|
/// 使用角色模型渲染
|
||||||
- (void)renderWithTitle:(NSString *)title rank:(NSInteger)rank;
|
- (void)renderWithCharacter:(KBCharacter *)character rank:(NSInteger)rank;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation KBTopThreeCardView
|
@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 : @"";
|
self.titleLabel.text = title.length ? title : @"";
|
||||||
|
|
||||||
// 不同名次数的配色
|
// 不同名次数的配色
|
||||||
@@ -80,7 +82,9 @@
|
|||||||
} break; // 橙
|
} break; // 橙
|
||||||
}
|
}
|
||||||
self.cardImageView.image = image;
|
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;
|
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.backgroundColor = [UIColor whiteColor];
|
||||||
_avatarCircleView.layer.cornerRadius = 34;
|
_avatarCircleView.layer.cornerRadius = 34;
|
||||||
_avatarCircleView.layer.borderWidth = 2.0;
|
_avatarCircleView.layer.borderWidth = 2.0;
|
||||||
|
_avatarCircleView.layer.masksToBounds = true;
|
||||||
}
|
}
|
||||||
return _avatarCircleView;
|
return _avatarCircleView;
|
||||||
}
|
}
|
||||||
@@ -197,19 +202,22 @@
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)configWithItems:(NSArray<NSDictionary *> *)items {
|
- (void)configWithCharacters:(NSArray<KBCharacter *> *)characters {
|
||||||
// items 顺序任意,这里按 rank 分配:1 放中间,2 左,3 右
|
if (characters.count == 0) {
|
||||||
NSString *t1 = @"", *t2 = @"", *t3 = @"";
|
// 无数据时清空标题与头像
|
||||||
for (NSDictionary *d in items) {
|
[self.centerCard renderWithCharacter:[KBCharacter new] rank:1];
|
||||||
NSInteger r = [d[@"rank"] integerValue];
|
[self.leftCard renderWithCharacter:[KBCharacter new] rank:2];
|
||||||
NSString *title = d[@"title"] ?: @"";
|
[self.rightCard renderWithCharacter:[KBCharacter new] rank:3];
|
||||||
if (r == 1) t1 = title;
|
return;
|
||||||
else if (r == 2) t2 = title;
|
|
||||||
else if (r == 3) t3 = title;
|
|
||||||
}
|
}
|
||||||
[self.centerCard renderWithTitle:t1 rank:1];
|
|
||||||
[self.leftCard renderWithTitle:t2 rank:2];
|
KBCharacter *first = characters.count > 0 ? characters[0] : nil;
|
||||||
[self.rightCard renderWithTitle:t3 rank:3];
|
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
|
#pragma mark - Lazy
|
||||||
|
|||||||
@@ -63,17 +63,12 @@
|
|||||||
}
|
}
|
||||||
weakSelf.allCharacters = list ?: @[];
|
weakSelf.allCharacters = list ?: @[];
|
||||||
|
|
||||||
// 顶部前三名数据
|
// 顶部前三名数据:直接取前三个模型交给 KBTopThreeView
|
||||||
NSMutableArray *topItems = [NSMutableArray array];
|
|
||||||
NSInteger topCount = MIN(3, weakSelf.allCharacters.count);
|
NSInteger topCount = MIN(3, weakSelf.allCharacters.count);
|
||||||
for (NSInteger i = 0; i < topCount; i++) {
|
if (topCount > 0) {
|
||||||
KBCharacter *c = weakSelf.allCharacters[i];
|
NSRange range = NSMakeRange(0, topCount);
|
||||||
// NSInteger rank = (c.rank > 0) ? c.rank : (i + 1);
|
NSArray<KBCharacter *> *topThree = [weakSelf.allCharacters subarrayWithRange:range];
|
||||||
NSString *title = c.characterName ?: @"";
|
[weakSelf.topThreeView configWithCharacters:topThree];
|
||||||
[topItems addObject:@{ @"title": title, @"rank": @(i + 1) }];
|
|
||||||
}
|
|
||||||
if (topItems.count > 0) {
|
|
||||||
[weakSelf.topThreeView configWithItems:topItems];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列表部分:从第 4 名开始
|
// 列表部分:从第 4 名开始
|
||||||
|
|||||||
Reference in New Issue
Block a user