
- 创建 NewMomentViewController(OC) * 列表式布局 + 下拉刷新 + 滚动加载 * 发布按钮(右下角悬浮) * 使用模拟数据 - 创建 NewMomentCell(OC) * 卡片式设计(白色卡片 + 阴影) * 圆角矩形头像(不是圆形!) * 底部操作栏(点赞/评论/分享) - 创建 NewMineViewController(OC) * TableView 布局 + 8 个菜单项 * 设置按钮(右上角) - 创建 NewMineHeaderView(OC) * 渐变背景(蓝色系) * 圆角矩形头像 + 白色边框 * 昵称、等级、经验进度条 * 关注/粉丝统计 * 纵向卡片式设计 - 集成到 NewTabBarController * 使用真实的 ViewController 替换占位 * 支持登录前/后状态切换 - 更新 Bridging Header * 添加新模块的 OC 类引用 - 创建测试指南文档 * 如何运行新 TabBar * 测试清单 * 常见问题解答 新增文件: - NewMomentViewController.h/m - NewMomentCell.h/m - NewMineViewController.h/m - NewMineHeaderView.h/m - white-label-test-guide.md 代码量:约 1500 行
279 lines
8.9 KiB
Objective-C
279 lines
8.9 KiB
Objective-C
//
|
|
// NewMineHeaderView.m
|
|
// YuMi
|
|
//
|
|
// Created by AI on 2025-10-09.
|
|
// Copyright © 2025 YuMi. All rights reserved.
|
|
//
|
|
|
|
#import "NewMineHeaderView.h"
|
|
#import <Masonry/Masonry.h>
|
|
|
|
@interface NewMineHeaderView ()
|
|
|
|
// MARK: - UI Components
|
|
|
|
/// 渐变背景层
|
|
@property (nonatomic, strong) CAGradientLayer *gradientLayer;
|
|
|
|
/// 头像(大尺寸,圆角矩形)
|
|
@property (nonatomic, strong) UIImageView *avatarImageView;
|
|
|
|
/// 昵称
|
|
@property (nonatomic, strong) UILabel *nicknameLabel;
|
|
|
|
/// 等级标签
|
|
@property (nonatomic, strong) UILabel *levelLabel;
|
|
|
|
/// 经验进度条容器
|
|
@property (nonatomic, strong) UIView *progressContainer;
|
|
|
|
/// 经验进度条
|
|
@property (nonatomic, strong) UIView *progressBar;
|
|
|
|
/// 经验文本
|
|
@property (nonatomic, strong) UILabel *expLabel;
|
|
|
|
/// 统计容器
|
|
@property (nonatomic, strong) UIView *statsContainer;
|
|
|
|
/// 关注数标签
|
|
@property (nonatomic, strong) UILabel *followingLabel;
|
|
|
|
/// 粉丝数标签
|
|
@property (nonatomic, strong) UILabel *followersLabel;
|
|
|
|
@end
|
|
|
|
@implementation NewMineHeaderView
|
|
|
|
// MARK: - Lifecycle
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
if (self = [super initWithFrame:frame]) {
|
|
[self setupUI];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)layoutSubviews {
|
|
[super layoutSubviews];
|
|
|
|
// 更新渐变层大小
|
|
self.gradientLayer.frame = self.bounds;
|
|
}
|
|
|
|
// MARK: - Setup UI
|
|
|
|
- (void)setupUI {
|
|
// 渐变背景(新的配色方案)
|
|
self.gradientLayer = [CAGradientLayer layer];
|
|
self.gradientLayer.colors = @[
|
|
(id)[UIColor colorWithRed:0.2 green:0.6 blue:0.86 alpha:1.0].CGColor, // 主色调
|
|
(id)[UIColor colorWithRed:0.3 green:0.5 blue:0.9 alpha:1.0].CGColor, // 渐变色
|
|
];
|
|
self.gradientLayer.startPoint = CGPointMake(0, 0);
|
|
self.gradientLayer.endPoint = CGPointMake(1, 1);
|
|
[self.layer insertSublayer:self.gradientLayer atIndex:0];
|
|
|
|
// 头像(大尺寸,圆角矩形)
|
|
[self addSubview:self.avatarImageView];
|
|
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.equalTo(self);
|
|
make.top.equalTo(self).offset(40);
|
|
make.size.mas_equalTo(CGSizeMake(80, 80));
|
|
}];
|
|
|
|
// 昵称
|
|
[self addSubview:self.nicknameLabel];
|
|
[self.nicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.equalTo(self);
|
|
make.top.equalTo(self.avatarImageView.mas_bottom).offset(15);
|
|
}];
|
|
|
|
// 等级标签
|
|
[self addSubview:self.levelLabel];
|
|
[self.levelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.equalTo(self);
|
|
make.top.equalTo(self.nicknameLabel.mas_bottom).offset(8);
|
|
}];
|
|
|
|
// 经验进度条容器
|
|
[self addSubview:self.progressContainer];
|
|
[self.progressContainer mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.equalTo(self).offset(40);
|
|
make.right.equalTo(self).offset(-40);
|
|
make.top.equalTo(self.levelLabel.mas_bottom).offset(15);
|
|
make.height.mas_equalTo(8);
|
|
}];
|
|
|
|
// 经验进度条
|
|
[self.progressContainer addSubview:self.progressBar];
|
|
[self.progressBar mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.top.bottom.equalTo(self.progressContainer);
|
|
make.width.equalTo(self.progressContainer).multipliedBy(0.7); // 默认 70%
|
|
}];
|
|
|
|
// 经验文本
|
|
[self addSubview:self.expLabel];
|
|
[self.expLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.equalTo(self);
|
|
make.top.equalTo(self.progressContainer.mas_bottom).offset(6);
|
|
}];
|
|
|
|
// 统计容器
|
|
[self addSubview:self.statsContainer];
|
|
[self.statsContainer mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.equalTo(self);
|
|
make.top.equalTo(self.expLabel.mas_bottom).offset(20);
|
|
make.height.mas_equalTo(60);
|
|
make.bottom.equalTo(self).offset(-15);
|
|
}];
|
|
|
|
// 关注数
|
|
[self.statsContainer addSubview:self.followingLabel];
|
|
[self.followingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.equalTo(self.statsContainer.mas_centerX).offset(-20);
|
|
make.centerY.equalTo(self.statsContainer);
|
|
}];
|
|
|
|
// 粉丝数
|
|
[self.statsContainer addSubview:self.followersLabel];
|
|
[self.followersLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.equalTo(self.statsContainer.mas_centerX).offset(20);
|
|
make.centerY.equalTo(self.statsContainer);
|
|
}];
|
|
}
|
|
|
|
// MARK: - Public Methods
|
|
|
|
- (void)configureWithUserInfo:(NSDictionary *)userInfo {
|
|
// 配置昵称
|
|
self.nicknameLabel.text = userInfo[@"nickname"] ?: @"未设置昵称";
|
|
|
|
// 配置等级
|
|
NSNumber *level = userInfo[@"level"];
|
|
self.levelLabel.text = [NSString stringWithFormat:@"Lv.%@", level ?: @"0"];
|
|
|
|
// 配置经验
|
|
NSNumber *exp = userInfo[@"exp"];
|
|
NSNumber *nextLevelExp = userInfo[@"nextLevelExp"];
|
|
CGFloat progress = [exp floatValue] / [nextLevelExp floatValue];
|
|
[self.progressBar mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.top.bottom.equalTo(self.progressContainer);
|
|
make.width.equalTo(self.progressContainer).multipliedBy(MAX(0.1, MIN(1.0, progress)));
|
|
}];
|
|
self.expLabel.text = [NSString stringWithFormat:@"%@ / %@", exp, nextLevelExp];
|
|
|
|
// 配置统计
|
|
NSNumber *followers = userInfo[@"followers"];
|
|
NSNumber *following = userInfo[@"following"];
|
|
self.followingLabel.text = [NSString stringWithFormat:@"关注\n%@", following ?: @"0"];
|
|
self.followersLabel.text = [NSString stringWithFormat:@"粉丝\n%@", followers ?: @"0"];
|
|
|
|
NSLog(@"[NewMineHeaderView] 用户信息已配置: %@", userInfo[@"nickname"]);
|
|
}
|
|
|
|
// MARK: - Lazy Loading
|
|
|
|
- (UIImageView *)avatarImageView {
|
|
if (!_avatarImageView) {
|
|
_avatarImageView = [[UIImageView alloc] init];
|
|
_avatarImageView.backgroundColor = [UIColor whiteColor];
|
|
_avatarImageView.layer.cornerRadius = 16; // 圆角矩形
|
|
_avatarImageView.layer.masksToBounds = YES;
|
|
_avatarImageView.layer.borderWidth = 3;
|
|
_avatarImageView.layer.borderColor = [UIColor whiteColor].CGColor;
|
|
_avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
}
|
|
return _avatarImageView;
|
|
}
|
|
|
|
- (UILabel *)nicknameLabel {
|
|
if (!_nicknameLabel) {
|
|
_nicknameLabel = [[UILabel alloc] init];
|
|
_nicknameLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightBold];
|
|
_nicknameLabel.textColor = [UIColor whiteColor];
|
|
_nicknameLabel.textAlignment = NSTextAlignmentCenter;
|
|
}
|
|
return _nicknameLabel;
|
|
}
|
|
|
|
- (UILabel *)levelLabel {
|
|
if (!_levelLabel) {
|
|
_levelLabel = [[UILabel alloc] init];
|
|
_levelLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
|
|
_levelLabel.textColor = [UIColor colorWithWhite:1.0 alpha:0.9];
|
|
_levelLabel.textAlignment = NSTextAlignmentCenter;
|
|
_levelLabel.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.2];
|
|
_levelLabel.layer.cornerRadius = 12;
|
|
_levelLabel.layer.masksToBounds = YES;
|
|
|
|
// 添加内边距
|
|
_levelLabel.text = @" Lv.0 ";
|
|
}
|
|
return _levelLabel;
|
|
}
|
|
|
|
- (UIView *)progressContainer {
|
|
if (!_progressContainer) {
|
|
_progressContainer = [[UIView alloc] init];
|
|
_progressContainer.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.3];
|
|
_progressContainer.layer.cornerRadius = 4;
|
|
_progressContainer.layer.masksToBounds = YES;
|
|
}
|
|
return _progressContainer;
|
|
}
|
|
|
|
- (UIView *)progressBar {
|
|
if (!_progressBar) {
|
|
_progressBar = [[UIView alloc] init];
|
|
_progressBar.backgroundColor = [UIColor whiteColor];
|
|
_progressBar.layer.cornerRadius = 4;
|
|
_progressBar.layer.masksToBounds = YES;
|
|
}
|
|
return _progressBar;
|
|
}
|
|
|
|
- (UILabel *)expLabel {
|
|
if (!_expLabel) {
|
|
_expLabel = [[UILabel alloc] init];
|
|
_expLabel.font = [UIFont systemFontOfSize:12];
|
|
_expLabel.textColor = [UIColor colorWithWhite:1.0 alpha:0.8];
|
|
_expLabel.textAlignment = NSTextAlignmentCenter;
|
|
}
|
|
return _expLabel;
|
|
}
|
|
|
|
- (UIView *)statsContainer {
|
|
if (!_statsContainer) {
|
|
_statsContainer = [[UIView alloc] init];
|
|
_statsContainer.backgroundColor = [UIColor clearColor];
|
|
}
|
|
return _statsContainer;
|
|
}
|
|
|
|
- (UILabel *)followingLabel {
|
|
if (!_followingLabel) {
|
|
_followingLabel = [[UILabel alloc] init];
|
|
_followingLabel.font = [UIFont systemFontOfSize:14];
|
|
_followingLabel.textColor = [UIColor whiteColor];
|
|
_followingLabel.textAlignment = NSTextAlignmentCenter;
|
|
_followingLabel.numberOfLines = 2;
|
|
}
|
|
return _followingLabel;
|
|
}
|
|
|
|
- (UILabel *)followersLabel {
|
|
if (!_followersLabel) {
|
|
_followersLabel = [[UILabel alloc] init];
|
|
_followersLabel.font = [UIFont systemFontOfSize:14];
|
|
_followersLabel.textColor = [UIColor whiteColor];
|
|
_followersLabel.textAlignment = NSTextAlignmentCenter;
|
|
_followersLabel.numberOfLines = 2;
|
|
}
|
|
return _followersLabel;
|
|
}
|
|
|
|
@end
|