Files
keyboard/keyBoard/Class/Me/VC/KBPersonInfoVC.m
2025-11-11 14:56:57 +08:00

248 lines
9.1 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// KBPersonInfoVC.m
// keyBoard
//
// Created by Mac on 2025/11/11.
//
//
// KBPersonInfoVC.m
// 个人资料
//
#import "KBPersonInfoVC.h"
#import <Masonry/Masonry.h>
#import "KBPersonInfoItemCell.h"
@interface KBPersonInfoVC () <UITableViewDelegate, UITableViewDataSource>
// 列表
@property (nonatomic, strong) BaseTableView *tableView; // 懒加载
// 头像区(表头)
@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) UIImageView *avatarView; // 头像
@property (nonatomic, strong) UIButton *editBadge; // 头像右下角的小铅笔
@property (nonatomic, strong) UILabel *modifyLabel; // “Modify” 文案
// 底部退出(表尾)
@property (nonatomic, strong) UIView *footerView;
@property (nonatomic, strong) UIView *logoutBg;
@property (nonatomic, strong) UIButton *logoutBtn;
// 数据
@property (nonatomic, copy) NSArray<NSDictionary *> *items; // {title,value,arrow,copy}
@end
@implementation KBPersonInfoVC
- (void)viewDidLoad {
[super viewDidLoad];
self.kb_titleLabel.text = @"Settings"; // 导航标题
self.kb_navView.backgroundColor = [UIColor clearColor];
self.view.backgroundColor = [UIColor colorWithHex:0xF8F8F8];
// 构造数据
self.items = @[
@{ @"title": @"Nickname", @"value": @"Nickname", @"arrow": @YES, @"copy": @NO },
@{ @"title": @"Gender", @"value": @"Choose", @"arrow": @YES, @"copy": @NO },
@{ @"title": @"User ID", @"value": @"8888888", @"arrow": @NO, @"copy": @YES },
];
[self.view addSubview:self.tableView];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.equalTo(self.view);
make.top.equalTo(self.view).offset(KB_NAV_TOTAL_HEIGHT + 10);
}];
// 表头 & 表尾
self.tableView.tableHeaderView = self.headerView;
self.tableView.tableFooterView = self.footerView;
}
#pragma mark - UITableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.items.count; }
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 56.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 12.0; }
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { return [UIView new]; }
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.01; }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cid = @"KBPersonInfoItemCell";
KBPersonInfoItemCell *cell = [tableView dequeueReusableCellWithIdentifier:cid];
if (!cell) { cell = [[KBPersonInfoItemCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cid]; }
NSDictionary *it = self.items[indexPath.row];
BOOL isTop = (indexPath.row == 0);
BOOL isBottom = (indexPath.row == self.items.count - 1);
[cell configWithTitle:it[@"title"]
value:it[@"value"]
showArrow:[it[@"arrow"] boolValue]
showCopy:[it[@"copy"] boolValue]
isTop:isTop
isBottom:isBottom];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// 示例:点击昵称/性别执行操作;用户 ID 行点击不处理(有复制按钮)
if (indexPath.row == 0) {
// TODO: 昵称编辑
} else if (indexPath.row == 1) {
// TODO: 性别选择
}
}
#pragma mark - Actions
- (void)onTapAvatarEdit {
// 示例:更换头像
}
- (void)onTapLogout {
// 示例:退出登录
}
#pragma mark - Lazy UI懒加载
- (UITableView *)tableView {
if (!_tableView) {
// 使用 Plain自行实现卡片留白与圆角更贴近设计图
_tableView = [[BaseTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.backgroundColor = UIColor.clearColor;
_tableView.showsVerticalScrollIndicator = NO;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone; // 自定义分割
_tableView.dataSource = self; _tableView.delegate = self;
_tableView.contentInset = UIEdgeInsetsMake(8, 0, 16, 0);
}
return _tableView;
}
- (UIView *)headerView {
if (!_headerView) {
CGFloat w = UIScreen.mainScreen.bounds.size.width;
UIView *hv = [[UIView alloc] initWithFrame:CGRectMake(0, 0, w, 180)];
hv.backgroundColor = UIColor.clearColor;
[hv addSubview:self.avatarView];
[hv addSubview:self.editBadge];
[hv addSubview:self.modifyLabel];
[self.avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(hv);
make.top.equalTo(hv).offset(12);
make.width.height.mas_equalTo(96);
}];
[self.editBadge mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(24);
make.centerX.equalTo(self.avatarView.mas_right).offset(-8);
make.centerY.equalTo(self.avatarView.mas_bottom).offset(-8);
}];
[self.modifyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.avatarView.mas_bottom).offset(10);
make.centerX.equalTo(hv);
}];
_headerView = hv;
}
return _headerView;
}
- (UIImageView *)avatarView {
if (!_avatarView) {
_avatarView = [[UIImageView alloc] init];
_avatarView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
_avatarView.layer.cornerRadius = 48; _avatarView.layer.masksToBounds = YES;
// 外白描边
_avatarView.layer.borderWidth = 3.0; _avatarView.layer.borderColor = UIColor.whiteColor.CGColor;
// 占位图
UIGraphicsBeginImageContextWithOptions(CGSizeMake(96, 96), NO, 0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor colorWithRed:0.86 green:0.95 blue:0.90 alpha:1] setFill];
CGContextFillEllipseInRect(ctx, CGRectMake(0, 0, 96, 96));
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
_avatarView.image = img;
_avatarView.userInteractionEnabled = YES;
}
return _avatarView;
}
- (UIButton *)editBadge {
if (!_editBadge) {
_editBadge = [UIButton buttonWithType:UIButtonTypeCustom];
_editBadge.backgroundColor = [UIColor colorWithRed:0.02 green:0.75 blue:0.67 alpha:1.0];
_editBadge.layer.cornerRadius = 12; _editBadge.layer.masksToBounds = YES;
UIImage *img = nil;
if (@available(iOS 13.0, *)) img = [UIImage systemImageNamed:@"pencil"]; // 铅笔图标
[_editBadge setImage:img forState:UIControlStateNormal];
[_editBadge setTitle:(img ? @"" : @"") forState:UIControlStateNormal];
_editBadge.titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightBold];
[_editBadge setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
[_editBadge addTarget:self action:@selector(onTapAvatarEdit) forControlEvents:UIControlEventTouchUpInside];
}
return _editBadge;
}
- (UILabel *)modifyLabel {
if (!_modifyLabel) {
_modifyLabel = [UILabel new];
_modifyLabel.text = @"Modify";
_modifyLabel.textColor = [UIColor blackColor];
_modifyLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
}
return _modifyLabel;
}
- (UIView *)footerView {
if (!_footerView) {
CGFloat w = UIScreen.mainScreen.bounds.size.width;
UIView *fv = [[UIView alloc] initWithFrame:CGRectMake(0, 0, w, 120)];
fv.backgroundColor = UIColor.clearColor;
[fv addSubview:self.logoutBg];
[self.logoutBg mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(fv).offset(16);
make.right.equalTo(fv).offset(-16);
make.top.equalTo(fv).offset(14);
make.height.mas_equalTo(56);
}];
[self.logoutBg addSubview:self.logoutBtn];
[self.logoutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.logoutBg);
}];
_footerView = fv;
}
return _footerView;
}
- (UIView *)logoutBg {
if (!_logoutBg) {
_logoutBg = [UIView new];
_logoutBg.backgroundColor = UIColor.whiteColor;
_logoutBg.layer.cornerRadius = 12; _logoutBg.layer.masksToBounds = YES;
}
return _logoutBg;
}
- (UIButton *)logoutBtn {
if (!_logoutBtn) {
_logoutBtn = [UIButton buttonWithType:UIButtonTypeSystem];
[_logoutBtn setTitle:@"Log Out" forState:UIControlStateNormal];
[_logoutBtn setTitleColor:[UIColor colorWithRed:0.85 green:0.15 blue:0.11 alpha:1.0] forState:UIControlStateNormal];
_logoutBtn.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
[_logoutBtn addTarget:self action:@selector(onTapLogout) forControlEvents:UIControlEventTouchUpInside];
}
return _logoutBtn;
}
@end