优化ui
This commit is contained in:
27
keyBoard/Class/Home/V/HomeRankCardCell.h
Normal file
27
keyBoard/Class/Home/V/HomeRankCardCell.h
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// HomeRankCardCell.h
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Codex on 2025/11/06.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/// 首页排行榜卡片 Cell(两列)
|
||||
@interface HomeRankCardCell : UICollectionViewCell
|
||||
|
||||
/// 点击加号/勾选按钮回调
|
||||
@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
|
||||
|
||||
202
keyBoard/Class/Home/V/HomeRankCardCell.m
Normal file
202
keyBoard/Class/Home/V/HomeRankCardCell.m
Normal file
@@ -0,0 +1,202 @@
|
||||
//
|
||||
// HomeRankCardCell.m
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Codex on 2025/11/06.
|
||||
//
|
||||
|
||||
@import UIKit;
|
||||
#import "HomeRankCardCell.h"
|
||||
|
||||
@interface HomeRankCardCell ()
|
||||
@property (nonatomic, strong) UIView *shadowView; // 阴影容器(不裁剪)
|
||||
@property (nonatomic, strong) UIView *cardView; // 白色圆角卡片
|
||||
@property (nonatomic, strong) UIView *badgeCircle; // 顶部圆形描边
|
||||
@property (nonatomic, strong) UILabel *titleLabel;
|
||||
@property (nonatomic, strong) UILabel *descLabel;
|
||||
@property (nonatomic, strong) UILabel *peopleLabel;
|
||||
@property (nonatomic, strong) UIButton *actionBtn; // 加号/勾选按钮
|
||||
@property (nonatomic, assign) BOOL added;
|
||||
@end
|
||||
|
||||
@implementation HomeRankCardCell
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
self.contentView.backgroundColor = UIColor.clearColor;
|
||||
[self setupUI];
|
||||
[self setupConstraints];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setupUI {
|
||||
// 使用懒加载属性,保证首次访问时创建
|
||||
[self.contentView addSubview:self.shadowView];
|
||||
[self.shadowView addSubview:self.cardView];
|
||||
[self.contentView addSubview:self.badgeCircle];
|
||||
[self.cardView addSubview:self.titleLabel];
|
||||
[self.cardView addSubview:self.descLabel];
|
||||
[self.cardView addSubview:self.peopleLabel];
|
||||
[self.cardView addSubview:self.actionBtn];
|
||||
}
|
||||
|
||||
- (void)setupConstraints {
|
||||
// Masonry 约束
|
||||
[self.shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.bottom.equalTo(self.contentView);
|
||||
make.top.equalTo(self.contentView.mas_top).offset(36); // 给圆环留空间
|
||||
}];
|
||||
|
||||
[self.cardView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(self.shadowView).insets(UIEdgeInsetsMake(0, 8, 0, 8));
|
||||
}];
|
||||
|
||||
[self.badgeCircle 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.cardView.mas_top).offset(78);
|
||||
make.left.equalTo(self.cardView.mas_left).offset(18);
|
||||
make.right.equalTo(self.cardView.mas_right).offset(-18);
|
||||
}];
|
||||
|
||||
[self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.titleLabel.mas_bottom).offset(12);
|
||||
make.left.equalTo(self.cardView.mas_left).offset(18);
|
||||
make.right.equalTo(self.cardView.mas_right).offset(-18);
|
||||
}];
|
||||
|
||||
[self.peopleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.descLabel.mas_bottom).offset(16);
|
||||
make.left.equalTo(self.cardView.mas_left).offset(18);
|
||||
make.right.equalTo(self.cardView.mas_right).offset(-18);
|
||||
}];
|
||||
|
||||
[self.actionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.cardView.mas_left).offset(18);
|
||||
make.right.equalTo(self.cardView.mas_right).offset(-18);
|
||||
make.bottom.equalTo(self.cardView.mas_bottom).offset(-18);
|
||||
make.height.mas_equalTo(56);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
// 添加柔和阴影
|
||||
_shadowView.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.15].CGColor;
|
||||
_shadowView.layer.shadowOpacity = 1.0;
|
||||
_shadowView.layer.shadowRadius = 10.0;
|
||||
_shadowView.layer.shadowOffset = CGSizeMake(0, 6);
|
||||
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:_cardView.bounds cornerRadius:18.0];
|
||||
_shadowView.layer.shadowPath = path.CGPath;
|
||||
|
||||
_badgeCircle.layer.cornerRadius = 34;
|
||||
}
|
||||
|
||||
- (void)prepareForReuse {
|
||||
[super prepareForReuse];
|
||||
self.onTapAction = nil;
|
||||
}
|
||||
|
||||
- (void)tapAction {
|
||||
if (self.onTapAction) self.onTapAction();
|
||||
}
|
||||
|
||||
- (void)configureWithTitle:(NSString *)title desc:(NSString *)desc people:(NSString *)people added:(BOOL)added {
|
||||
self.added = added;
|
||||
self.titleLabel.text = title ?: @"";
|
||||
self.descLabel.text = desc ?: @"";
|
||||
self.peopleLabel.text = people ?: @"";
|
||||
|
||||
if (added) {
|
||||
// 已添加:灰底、对勾
|
||||
self.actionBtn.backgroundColor = [UIColor colorWithWhite:0.93 alpha:1.0];
|
||||
[self.actionBtn setTitle:@"✓" forState:UIControlStateNormal];
|
||||
[self.actionBtn setTitleColor:[UIColor colorWithWhite:0.55 alpha:1.0] forState:UIControlStateNormal];
|
||||
} else {
|
||||
// 未添加:黑底、加号
|
||||
self.actionBtn.backgroundColor = [UIColor blackColor];
|
||||
[self.actionBtn setTitle:@"+" forState:UIControlStateNormal];
|
||||
[self.actionBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Lazy UI
|
||||
|
||||
- (UIView *)shadowView {
|
||||
if (!_shadowView) {
|
||||
_shadowView = [UIView new];
|
||||
_shadowView.backgroundColor = UIColor.clearColor;
|
||||
}
|
||||
return _shadowView;
|
||||
}
|
||||
|
||||
- (UIView *)cardView {
|
||||
if (!_cardView) {
|
||||
_cardView = [UIView new];
|
||||
_cardView.backgroundColor = UIColor.whiteColor;
|
||||
_cardView.layer.cornerRadius = 18.0;
|
||||
_cardView.layer.masksToBounds = YES;
|
||||
}
|
||||
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;
|
||||
}
|
||||
return _badgeCircle;
|
||||
}
|
||||
|
||||
- (UILabel *)titleLabel {
|
||||
if (!_titleLabel) {
|
||||
_titleLabel = [UILabel new];
|
||||
_titleLabel.textColor = [UIColor colorWithWhite:0 alpha:0.95];
|
||||
_titleLabel.font = [UIFont systemFontOfSize:26 weight:UIFontWeightSemibold];
|
||||
_titleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
}
|
||||
return _titleLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)descLabel {
|
||||
if (!_descLabel) {
|
||||
_descLabel = [UILabel new];
|
||||
_descLabel.textColor = [UIColor colorWithWhite:0.45 alpha:1];
|
||||
_descLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightRegular];
|
||||
_descLabel.textAlignment = NSTextAlignmentCenter;
|
||||
_descLabel.numberOfLines = 2;
|
||||
}
|
||||
return _descLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)peopleLabel {
|
||||
if (!_peopleLabel) {
|
||||
_peopleLabel = [UILabel new];
|
||||
_peopleLabel.textColor = [UIColor colorWithRed:0.31 green:0.78 blue:0.63 alpha:1.0];
|
||||
_peopleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
|
||||
_peopleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
_peopleLabel.numberOfLines = 2;
|
||||
}
|
||||
return _peopleLabel;
|
||||
}
|
||||
|
||||
- (UIButton *)actionBtn {
|
||||
if (!_actionBtn) {
|
||||
_actionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
_actionBtn.layer.cornerRadius = 12.0;
|
||||
_actionBtn.layer.masksToBounds = YES;
|
||||
[_actionBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
|
||||
_actionBtn.titleLabel.font = [UIFont systemFontOfSize:28 weight:UIFontWeightSemibold];
|
||||
[_actionBtn addTarget:self action:@selector(tapAction) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _actionBtn;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -103,7 +103,7 @@
|
||||
if (self.currentIndex == 0) {
|
||||
return self.hotVC.tableView;
|
||||
}
|
||||
return self.rankVC.tableView;
|
||||
return self.rankVC.collectionView;
|
||||
}
|
||||
|
||||
// 可选:完全不允许拖拽关闭(避免被拉到底消失)
|
||||
|
||||
Reference in New Issue
Block a user