
主要变更: 1. 在 EPEditSettingViewController 中添加了用户头像和相机图标的布局,提升用户界面友好性。 2. 引入 EPMineAPIHelper 以支持头像更新功能,简化 API 调用。 3. 优化了导航栏的显示和隐藏逻辑,确保用户体验流畅。 4. 更新了 UITableView 的数据源和布局,确保信息展示清晰。 此更新旨在提升用户体验,简化用户信息的管理和更新流程。
125 lines
4.1 KiB
Objective-C
125 lines
4.1 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;
|
|
|
|
@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.trailing.equalTo(self).offset(-20);
|
|
make.size.mas_equalTo(CGSizeMake(40, 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];
|
|
|
|
// 加载头像
|
|
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] 设置按钮点击");
|
|
// 使用 block 回调
|
|
if (self.onSettingsButtonTapped) {
|
|
self.onSettingsButtonTapped();
|
|
}
|
|
}
|
|
|
|
@end
|