Files
real-e-party-iOS/YuMi/Modules/NewMine/Views/EPMineHeaderView.m
edwinQQQ 12a8ef9a62 重构 Mine 模块为个人主页模式
 完成功能:
1. EPMineViewController 重构
   - 从菜单列表模式改为个人主页模式
   - 渐变背景(深紫到蓝)
   - 顶部个人信息卡片 + 底部用户动态列表
   - 复用 EPMomentCell 显示动态

2. EPMineHeaderView 新建
   - 大圆形头像(120x120,白色边框)
   - 昵称 + ID 显示
   - 关注/粉丝按钮
   - 右上角设置按钮
   - 渐变背景适配

3. 数据加载优化
   - 用户信息加载(真实 API)
   - 用户动态列表(分页加载)
   - 下拉刷新功能
   - 自动加载更多

4. 文件重命名
   - EPMomentCell(原 NewMomentCell)
   - EPMineHeaderView(新建)
   - 更新 Bridging Header

技术亮点:
- 个人主页模式完全不同于原版菜单模式
- 渐变背景 + 毛玻璃效果
- 复用 EPMomentCell 减少开发量
- 真实 API 集成

下一步:
- 修复编译错误(文件未添加到 Xcode 项目)
- 继续 v0.2 版本准备
2025-10-10 15:05:07 +08:00

165 lines
6.0 KiB
Objective-C

//
// EPMineHeaderView.m
// YuMi
//
// Created by AI on 2025-10-09.
// Copyright © 2025 YuMi. All rights reserved.
//
#import "EPMineHeaderView.h"
#import <Masonry/Masonry.h>
#import <SDWebImage/SDWebImage.h>
@interface EPMineHeaderView ()
/// 头像视图
@property (nonatomic, strong) UIImageView *avatarImageView;
/// 昵称标签
@property (nonatomic, strong) UILabel *nicknameLabel;
/// ID 标签
@property (nonatomic, strong) UILabel *idLabel;
/// 设置按钮
@property (nonatomic, strong) UIButton *settingsButton;
/// 关注按钮
@property (nonatomic, strong) UIButton *followButton;
/// 粉丝按钮
@property (nonatomic, strong) UIButton *fansButton;
@end
@implementation EPMineHeaderView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self setupUI];
}
return self;
}
- (void)setupUI {
// 大圆形头像
self.avatarImageView = [[UIImageView alloc] init];
self.avatarImageView.layer.cornerRadius = 60;
self.avatarImageView.layer.masksToBounds = YES;
self.avatarImageView.layer.borderWidth = 3;
self.avatarImageView.layer.borderColor = [UIColor whiteColor].CGColor;
self.avatarImageView.backgroundColor = [UIColor whiteColor];
self.avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
[self addSubview:self.avatarImageView];
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.top.equalTo(self).offset(60);
make.size.mas_equalTo(CGSizeMake(120, 120));
}];
// 昵称
self.nicknameLabel = [[UILabel alloc] init];
self.nicknameLabel.font = [UIFont boldSystemFontOfSize:24];
self.nicknameLabel.textColor = [UIColor whiteColor];
self.nicknameLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:self.nicknameLabel];
[self.nicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.top.equalTo(self.avatarImageView.mas_bottom).offset(16);
}];
// ID
self.idLabel = [[UILabel alloc] init];
self.idLabel.font = [UIFont systemFontOfSize:14];
self.idLabel.textColor = [UIColor whiteColor];
self.idLabel.alpha = 0.8;
self.idLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:self.idLabel];
[self.idLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.top.equalTo(self.nicknameLabel.mas_bottom).offset(8);
}];
// 设置按钮(右上角)
self.settingsButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.settingsButton setImage:[UIImage systemImageNamed:@"gearshape"] forState:UIControlStateNormal];
self.settingsButton.tintColor = [UIColor whiteColor];
self.settingsButton.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.2];
self.settingsButton.layer.cornerRadius = 20;
[self.settingsButton addTarget:self action:@selector(settingsButtonTapped) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.settingsButton];
[self.settingsButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self).offset(50);
make.right.equalTo(self).offset(-20);
make.size.mas_equalTo(CGSizeMake(40, 40));
}];
// 关注按钮
self.followButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.followButton setTitle:@"关注" forState:UIControlStateNormal];
[self.followButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.followButton.titleLabel.font = [UIFont systemFontOfSize:16];
self.followButton.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.2];
self.followButton.layer.cornerRadius = 20;
[self addSubview:self.followButton];
[self.followButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.idLabel.mas_bottom).offset(20);
make.centerX.equalTo(self).offset(-50);
make.size.mas_equalTo(CGSizeMake(80, 40));
}];
// 粉丝按钮
self.fansButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.fansButton setTitle:@"粉丝" forState:UIControlStateNormal];
[self.fansButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.fansButton.titleLabel.font = [UIFont systemFontOfSize:16];
self.fansButton.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.2];
self.fansButton.layer.cornerRadius = 20;
[self addSubview:self.fansButton];
[self.fansButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.idLabel.mas_bottom).offset(20);
make.centerX.equalTo(self).offset(50);
make.size.mas_equalTo(CGSizeMake(80, 40));
}];
}
- (void)updateWithUserInfo:(NSDictionary *)userInfoDict {
// 更新昵称
NSString *nickname = userInfoDict[@"nickname"] ?: @"未设置昵称";
self.nicknameLabel.text = nickname;
// 更新 ID
NSString *uid = userInfoDict[@"uid"] ?: @"";
self.idLabel.text = [NSString stringWithFormat:@"ID:%@", uid];
// 更新关注数
NSNumber *following = userInfoDict[@"following"] ?: @0;
[self.followButton setTitle:[NSString stringWithFormat:@"关注 %@", following] forState:UIControlStateNormal];
// 更新粉丝数
NSNumber *followers = userInfoDict[@"followers"] ?: @0;
[self.fansButton setTitle:[NSString stringWithFormat:@"粉丝 %@", followers] forState:UIControlStateNormal];
// 加载头像
NSString *avatarURL = userInfoDict[@"avatar"];
if (avatarURL && avatarURL.length > 0) {
[self.avatarImageView sd_setImageWithURL:[NSURL URLWithString:avatarURL]
placeholderImage:[UIImage imageNamed:@"default_avatar"]];
} else {
// 使用默认头像
self.avatarImageView.image = [UIImage imageNamed:@"default_avatar"];
}
}
- (void)settingsButtonTapped {
NSLog(@"[EPMineHeaderView] 设置按钮点击");
// TODO: 发送通知或回调给父视图
}
@end