diff --git a/keyBoard/Assets.xcassets/Ohter/placeholder_icon.imageset/Contents.json b/keyBoard/Assets.xcassets/Ohter/placeholder_icon.imageset/Contents.json new file mode 100644 index 0000000..278535e --- /dev/null +++ b/keyBoard/Assets.xcassets/Ohter/placeholder_icon.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "切图 223@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "切图 223@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/keyBoard/Assets.xcassets/Ohter/placeholder_icon.imageset/切图 223@2x.png b/keyBoard/Assets.xcassets/Ohter/placeholder_icon.imageset/切图 223@2x.png new file mode 100644 index 0000000..55939d9 Binary files /dev/null and b/keyBoard/Assets.xcassets/Ohter/placeholder_icon.imageset/切图 223@2x.png differ diff --git a/keyBoard/Assets.xcassets/Ohter/placeholder_icon.imageset/切图 223@3x.png b/keyBoard/Assets.xcassets/Ohter/placeholder_icon.imageset/切图 223@3x.png new file mode 100644 index 0000000..8c872d8 Binary files /dev/null and b/keyBoard/Assets.xcassets/Ohter/placeholder_icon.imageset/切图 223@3x.png differ diff --git a/keyBoard/Class/Home/V/HomeHotCell.m b/keyBoard/Class/Home/V/HomeHotCell.m index dd4be1e..6300c95 100644 --- a/keyBoard/Class/Home/V/HomeHotCell.m +++ b/keyBoard/Class/Home/V/HomeHotCell.m @@ -79,19 +79,7 @@ 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]; + [self.avatarView kb_setAvatarURL:character.avatarUrl placeholder:KBPlaceholderImage]; // 加入状态 BOOL joined = character.added; diff --git a/keyBoard/Class/Home/V/HomeRankCardCell.h b/keyBoard/Class/Home/V/HomeRankCardCell.h index bf523e3..ebc1670 100644 --- a/keyBoard/Class/Home/V/HomeRankCardCell.h +++ b/keyBoard/Class/Home/V/HomeRankCardCell.h @@ -13,18 +13,12 @@ NS_ASSUME_NONNULL_BEGIN /// 首页排行榜卡片 Cell(两列) @interface HomeRankCardCell : UICollectionViewCell -/// 当前展示的角色模型 +/// 当前展示的角色模型(设置后,cell 会在 setter 中根据模型刷新 UI) @property (nonatomic, strong, nullable) KBCharacter *character; /// 点击加号/勾选按钮回调 @property (nonatomic, copy, nullable) void (^onTapAction)(void); -/// 旧的配置方法(兼容用,不推荐继续使用) -- (void)configureWithTitle:(NSString *)title - desc:(NSString *)desc - people:(NSString *)people - added:(BOOL)added; - @end NS_ASSUME_NONNULL_END diff --git a/keyBoard/Class/Home/V/HomeRankCardCell.m b/keyBoard/Class/Home/V/HomeRankCardCell.m index 08b14b8..4cc3ff1 100644 --- a/keyBoard/Class/Home/V/HomeRankCardCell.m +++ b/keyBoard/Class/Home/V/HomeRankCardCell.m @@ -8,11 +8,12 @@ @import UIKit; #import "HomeRankCardCell.h" #import "UIView+KBShadow.h" +#import "UIImageView+KBWebImage.h" @interface HomeRankCardCell () @property (nonatomic, strong) UIView *shadowView; // 阴影容器(不裁剪) -@property (nonatomic, strong) UIImageView *cardView; // 卡片背景图片 -@property (nonatomic, strong) UIView *badgeCircle; // 顶部圆形描边 +@property (nonatomic, strong) UIView *cardView; // 卡片背景图片 +@property (nonatomic, strong) UIImageView *averImageView; // 顶部圆形描边 @property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UILabel *descLabel; @property (nonatomic, strong) UILabel *peopleLabel; @@ -35,7 +36,7 @@ // 使用懒加载属性,保证首次访问时创建 [self.contentView addSubview:self.shadowView]; [self.shadowView addSubview:self.cardView]; - [self.contentView addSubview:self.badgeCircle]; + [self.contentView addSubview:self.averImageView]; [self.cardView addSubview:self.titleLabel]; [self.cardView addSubview:self.descLabel]; [self.cardView addSubview:self.peopleLabel]; @@ -56,14 +57,14 @@ make.edges.equalTo(self.shadowView).insets(UIEdgeInsetsMake(0, 8, 0, 8)); }]; - [self.badgeCircle mas_makeConstraints:^(MASConstraintMaker *make) { + [self.averImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.cardView); make.centerY.equalTo(self.shadowView.mas_top); make.width.height.mas_equalTo(68); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { - make.top.equalTo(self.badgeCircle.mas_bottom).offset(13); + make.top.equalTo(self.averImageView.mas_bottom).offset(13); make.left.equalTo(self.cardView.mas_left).offset(18); make.right.equalTo(self.cardView.mas_right).offset(-18); make.height.mas_equalTo(23); @@ -94,7 +95,7 @@ // 阴影路径需在尺寸确定后更新(封装方法会基于记录参数自动计算) [self.shadowView kb_updateShadowPath]; - _badgeCircle.layer.cornerRadius = 34; + self.averImageView.layer.cornerRadius = 34; } - (void)prepareForReuse { @@ -106,12 +107,14 @@ if (self.onTapAction) self.onTapAction(); } -- (void)configureWithTitle:(NSString *)title desc:(NSString *)desc people:(NSString *)people added:(BOOL)added { +- (void)setCharacter:(KBCharacter *)character { + _character = character; + BOOL added = character.added; self.added = added; - self.titleLabel.text = title ?: @""; - self.descLabel.text = desc ?: @""; - self.peopleLabel.text = people ?: @""; - + self.titleLabel.text = character.characterName; + self.descLabel.text = character.characterBackground; + self.peopleLabel.text = character.download; + [self.averImageView kb_setAvatarURL:character.avatarUrl placeholder:KBPlaceholderImage]; if (added) { // 已添加:灰底、对勾 self.actionBtn.backgroundColor = [UIColor colorWithWhite:0.93 alpha:1.0]; @@ -125,17 +128,6 @@ } } -- (void)setCharacter:(KBCharacter *)character { - _character = character; - - NSString *title = character.characterName ?: @""; - NSString *people = character.download ?: @""; - NSString *desc = @"Be Neither Too Close\nNor Too Distant..."; // 目前暂无描述字段,先用示例文案 - BOOL added = character.added; - - [self configureWithTitle:title desc:desc people:people added:added]; -} - #pragma mark - Lazy UI - (UIView *)shadowView { @@ -146,27 +138,22 @@ return _shadowView; } -- (UIImageView *)cardView { +- (UIView *)cardView { if (!_cardView) { - _cardView = [[UIImageView alloc] init]; + _cardView = [[UIView alloc] init]; _cardView.backgroundColor = UIColor.whiteColor; - _cardView.layer.cornerRadius = 18.0; - _cardView.layer.masksToBounds = YES; - _cardView.contentMode = UIViewContentModeScaleAspectFill; - // 默认卡片背景图(可按需要替换) - _cardView.image = [UIImage imageNamed:@"home_rank_card_bg"]; } return _cardView; } -- (UIView *)badgeCircle { - if (!_badgeCircle) { - _badgeCircle = [UIView new]; - _badgeCircle.backgroundColor = UIColor.whiteColor; - _badgeCircle.layer.borderColor = [UIColor colorWithRed:0.78 green:0.90 blue:0.20 alpha:1.0].CGColor; - _badgeCircle.layer.borderWidth = 3.0; +- (UIImageView *)averImageView { + if (!_averImageView) { + _averImageView = [UIImageView new]; + _averImageView.backgroundColor = UIColor.whiteColor; + _averImageView.layer.borderColor = [UIColor colorWithRed:0.78 green:0.90 blue:0.20 alpha:1.0].CGColor; + _averImageView.layer.borderWidth = 3.0; } - return _badgeCircle; + return _averImageView; } - (UILabel *)titleLabel { diff --git a/keyBoard/KeyBoardPrefixHeader.pch b/keyBoard/KeyBoardPrefixHeader.pch index d5ce4da..30c7571 100644 --- a/keyBoard/KeyBoardPrefixHeader.pch +++ b/keyBoard/KeyBoardPrefixHeader.pch @@ -67,6 +67,8 @@ /// 第一次安装 #define KBSexSelectShownKey @"kKBSexSelectShownKey" +#define KBPlaceholderImage [UIImage imageNamed:@"placeholder_icon"] + /// UI 尺寸/设备宏 // 屏幕尺寸 #define KB_SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)