This commit is contained in:
2025-11-11 14:56:57 +08:00
parent 57bd4ba109
commit 17b8bf2bfd
6 changed files with 556 additions and 1 deletions

View File

@@ -0,0 +1,247 @@
//
// 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