This commit is contained in:
2025-12-03 18:53:15 +08:00
parent 82123fc232
commit 1d6371c37e
3 changed files with 58 additions and 21 deletions

View File

@@ -6,15 +6,21 @@
// //
#import "BaseCell.h" #import "BaseCell.h"
#import "KBCharacter.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface HomeHotCell : BaseCell @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 @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@@ -4,13 +4,14 @@
// //
#import "HomeHotCell.h" #import "HomeHotCell.h"
#import "UIImageView+KBWebImage.h"
@interface HomeHotCell() @interface HomeHotCell()
// //
@property (nonatomic, strong) UILabel *rankLabel; @property (nonatomic, strong) UILabel *rankLabel;
@property (nonatomic, strong) UIView *yuanView; @property (nonatomic, strong) UIView *yuanView;
// //
@property (nonatomic, strong) UIView *avatarView; @property (nonatomic, strong) UIImageView *avatarView;
// //
@property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UILabel *titleLabel;
// //
@@ -69,11 +70,31 @@
}]; }];
} }
- (void)configWithRank:(NSInteger)rank title:(NSString *)title subtitle:(NSString *)sub joined:(BOOL)joined { - (void)setCharacter:(KBCharacter *)character {
self.rankLabel.text = [NSString stringWithFormat:@"%ld", (long)rank]; _character = character;
self.titleLabel.text = title ?: @"";
self.subLabel.text = sub ?: @"";
//
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) { if (joined) {
// //
[self.actionButton setTitle:@"✓" forState:UIControlStateNormal]; [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 #pragma mark - Lazy
- (UILabel *)rankLabel { - (UILabel *)rankLabel {
@@ -98,12 +136,13 @@
return _rankLabel; return _rankLabel;
} }
- (UIView *)avatarView { - (UIImageView *)avatarView {
if (!_avatarView) { if (!_avatarView) {
_avatarView = [[UIView alloc] init]; _avatarView = [[UIImageView alloc] init];
_avatarView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1]; _avatarView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
_avatarView.layer.cornerRadius = 28; _avatarView.layer.cornerRadius = 28;
_avatarView.layer.masksToBounds = YES; _avatarView.layer.masksToBounds = YES;
_avatarView.contentMode = UIViewContentModeScaleAspectFill;
} }
return _avatarView; return _avatarView;
} }
@@ -148,4 +187,3 @@
} }
@end @end

View File

@@ -118,15 +118,8 @@
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
HomeHotCell *cell = [tableView dequeueReusableCellWithIdentifier:HomeHotCell.reuseId forIndexPath:indexPath]; HomeHotCell *cell = [tableView dequeueReusableCellWithIdentifier:HomeHotCell.reuseId forIndexPath:indexPath];
KBCharacter *item = self.listCharacters[indexPath.row]; KBCharacter *item = self.listCharacters[indexPath.row];
NSInteger rank = (item.rank > 0) ? item.rank : (indexPath.row + 4); // rank 4 // cell cell
NSString *title = item.characterName ?: @""; cell.character = item;
NSString *sub = item.download ?: @""; // download
BOOL joined = item.added;
// cell
[cell configWithRank:rank
title:title
subtitle:sub
joined:joined];
return cell; return cell;
} }