1
This commit is contained in:
@@ -6,15 +6,21 @@
|
||||
//
|
||||
|
||||
#import "BaseCell.h"
|
||||
#import "KBCharacter.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface HomeHotCell : BaseCell
|
||||
|
||||
/// 配置数据
|
||||
- (void)configWithRank:(NSInteger)rank title:(NSString *)title subtitle:(NSString *)sub joined:(BOOL)joined;
|
||||
/// 当前展示的排行榜角色模型
|
||||
@property (nonatomic, strong, nullable) KBCharacter *character;
|
||||
|
||||
/// 旧的配置方法(不再推荐使用),内部会转成 character 赋值
|
||||
- (void)configWithRank:(NSInteger)rank
|
||||
title:(NSString *)title
|
||||
subtitle:(NSString *)sub
|
||||
joined:(BOOL)joined;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
//
|
||||
|
||||
#import "HomeHotCell.h"
|
||||
#import "UIImageView+KBWebImage.h"
|
||||
|
||||
@interface HomeHotCell()
|
||||
// 左侧序号
|
||||
@property (nonatomic, strong) UILabel *rankLabel;
|
||||
@property (nonatomic, strong) UIView *yuanView;
|
||||
// 左侧圆形头像占位
|
||||
@property (nonatomic, strong) UIView *avatarView;
|
||||
// 左侧圆形头像
|
||||
@property (nonatomic, strong) UIImageView *avatarView;
|
||||
// 标题
|
||||
@property (nonatomic, strong) UILabel *titleLabel;
|
||||
// 副标题
|
||||
@@ -69,11 +70,31 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (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 ?: @"";
|
||||
- (void)setCharacter:(KBCharacter *)character {
|
||||
_character = character;
|
||||
|
||||
// 基本文案
|
||||
NSInteger rank = character.rank;
|
||||
self.rankLabel.text = rank > 0 ? [NSString stringWithFormat:@"%ld", (long)rank] : @"";
|
||||
self.titleLabel.text = character.characterName ?: @"";
|
||||
self.subLabel.text = character.download ?: @"";
|
||||
|
||||
// 头像:圆形占位 + 网络图
|
||||
UIImage *placeholder = nil;
|
||||
if (!placeholder) {
|
||||
// 使用纯色圆形作为占位
|
||||
CGFloat side = 56.0;
|
||||
UIGraphicsBeginImageContextWithOptions(CGSizeMake(side, side), NO, 0);
|
||||
CGContextRef ctx = UIGraphicsGetCurrentContext();
|
||||
[[UIColor colorWithWhite:0.9 alpha:1.0] setFill];
|
||||
CGContextFillEllipseInRect(ctx, CGRectMake(0, 0, side, side));
|
||||
placeholder = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
}
|
||||
[self.avatarView kb_setAvatarURL:character.avatarUrl placeholder:placeholder];
|
||||
|
||||
// 加入状态
|
||||
BOOL joined = character.added;
|
||||
if (joined) {
|
||||
// 已加入状态:灰背景、打勾
|
||||
[self.actionButton setTitle:@"✓" forState:UIControlStateNormal];
|
||||
@@ -87,6 +108,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 兼容旧调用:转成一个临时模型再走统一逻辑
|
||||
- (void)configWithRank:(NSInteger)rank title:(NSString *)title subtitle:(NSString *)sub joined:(BOOL)joined {
|
||||
KBCharacter *c = [KBCharacter new];
|
||||
c.rank = rank;
|
||||
c.characterName = title;
|
||||
c.download = sub;
|
||||
c.added = joined;
|
||||
self.character = c;
|
||||
}
|
||||
|
||||
- (void)prepareForReuse {
|
||||
[super prepareForReuse];
|
||||
[self.avatarView kb_cancelImageLoad];
|
||||
self.avatarView.image = nil;
|
||||
self.character = nil;
|
||||
}
|
||||
|
||||
#pragma mark - Lazy
|
||||
|
||||
- (UILabel *)rankLabel {
|
||||
@@ -98,12 +136,13 @@
|
||||
return _rankLabel;
|
||||
}
|
||||
|
||||
- (UIView *)avatarView {
|
||||
- (UIImageView *)avatarView {
|
||||
if (!_avatarView) {
|
||||
_avatarView = [[UIView alloc] init];
|
||||
_avatarView = [[UIImageView alloc] init];
|
||||
_avatarView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
|
||||
_avatarView.layer.cornerRadius = 28;
|
||||
_avatarView.layer.masksToBounds = YES;
|
||||
_avatarView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
}
|
||||
return _avatarView;
|
||||
}
|
||||
@@ -148,4 +187,3 @@
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -118,15 +118,8 @@
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
HomeHotCell *cell = [tableView dequeueReusableCellWithIdentifier:HomeHotCell.reuseId forIndexPath:indexPath];
|
||||
KBCharacter *item = self.listCharacters[indexPath.row];
|
||||
NSInteger rank = (item.rank > 0) ? item.rank : (indexPath.row + 4); // 兜底:接口没给 rank 时,从 4 开始递增
|
||||
NSString *title = item.characterName ?: @"";
|
||||
NSString *sub = item.download ?: @""; // 暂用 download 字段作为副标题展示
|
||||
BOOL joined = item.added;
|
||||
// 配置 cell
|
||||
[cell configWithRank:rank
|
||||
title:title
|
||||
subtitle:sub
|
||||
joined:joined];
|
||||
// 直接把模型交给 cell,由 cell 自己负责展示
|
||||
cell.character = item;
|
||||
return cell;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user