You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
390 lines
16 KiB
390 lines
16 KiB
//
|
|
// MyViewController.m
|
|
// HC
|
|
//
|
|
// Created by huilinLi on 2025/11/25.
|
|
//
|
|
|
|
#import "MyViewController.h"
|
|
#import <UIKit/UIKit.h>
|
|
#import "CommonTabBar.h"
|
|
#import "HomeViewController.h"
|
|
#import "ViewController.h"
|
|
#import "QuotationViewController.h"
|
|
|
|
@implementation MyViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
self.view.backgroundColor = [UIColor blackColor];
|
|
|
|
[self setupUI];
|
|
}
|
|
|
|
- (void)setupUI {
|
|
UIScrollView *scrollView = [[UIScrollView alloc] init];
|
|
scrollView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
scrollView.backgroundColor = [UIColor blackColor];
|
|
[self.view addSubview:scrollView];
|
|
|
|
UIView *contentView = [[UIView alloc] init];
|
|
contentView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
contentView.backgroundColor = [UIColor blackColor];
|
|
[scrollView addSubview:contentView];
|
|
|
|
[self setupUserHeaderInContentView:contentView];
|
|
[self setupCoinDiamondInContentView:contentView];
|
|
[self setupSettingListInContentView:contentView];
|
|
[self setupLogoutButtonInContentView:contentView];
|
|
[self setupTabBar];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[scrollView.topAnchor constraintEqualToAnchor:self.view.topAnchor],
|
|
[scrollView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
|
|
[scrollView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
|
|
[scrollView.bottomAnchor constraintEqualToAnchor:self.tabBar.topAnchor],
|
|
|
|
[contentView.topAnchor constraintEqualToAnchor:scrollView.topAnchor],
|
|
[contentView.leadingAnchor constraintEqualToAnchor:scrollView.leadingAnchor],
|
|
[contentView.trailingAnchor constraintEqualToAnchor:scrollView.trailingAnchor],
|
|
[contentView.bottomAnchor constraintEqualToAnchor:scrollView.bottomAnchor],
|
|
[contentView.widthAnchor constraintEqualToAnchor:scrollView.widthAnchor]
|
|
]];
|
|
}
|
|
|
|
#pragma mark - 上边儿
|
|
- (void)setupUserHeaderInContentView:(UIView *)contentView {
|
|
UIButton *settingBtn = [UIButton buttonWithType:UIButtonTypeSystem];
|
|
[settingBtn setImage:[UIImage systemImageNamed:@"gearshape"] forState:UIControlStateNormal];
|
|
settingBtn.tintColor = [UIColor whiteColor];
|
|
settingBtn.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[contentView addSubview:settingBtn];
|
|
|
|
UIImageView *avatar = [self createImageViewWithImage:@"hqz" contentMode:UIViewContentModeScaleAspectFill cornerRadius:40];
|
|
[contentView addSubview:avatar];
|
|
|
|
UILabel *nameLabel = [self createLabelWithText:@"演示机李慧琳" fontSize:18 textColor:[UIColor whiteColor]];
|
|
[contentView addSubview:nameLabel];
|
|
|
|
UILabel *idLabel = [self createLabelWithText:@"ID: 90047681" fontSize:14 textColor:[UIColor whiteColor]];
|
|
[contentView addSubview:idLabel];
|
|
|
|
UIButton *signBtn = [self createButtonWithTitle:@"已签到" bgColor:[UIColor whiteColor] cornerRadius:15];
|
|
[signBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
|
|
[contentView addSubview:signBtn];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[avatar.topAnchor constraintEqualToAnchor:contentView.topAnchor constant:20],
|
|
[avatar.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor constant:20],
|
|
[avatar.widthAnchor constraintEqualToConstant:80],
|
|
[avatar.heightAnchor constraintEqualToConstant:80],
|
|
|
|
[nameLabel.centerYAnchor constraintEqualToAnchor:avatar.centerYAnchor constant:-10],
|
|
[nameLabel.leadingAnchor constraintEqualToAnchor:avatar.trailingAnchor constant:15],
|
|
|
|
[idLabel.topAnchor constraintEqualToAnchor:nameLabel.bottomAnchor constant:5],
|
|
[idLabel.leadingAnchor constraintEqualToAnchor:nameLabel.leadingAnchor],
|
|
|
|
[signBtn.centerYAnchor constraintEqualToAnchor:avatar.centerYAnchor],
|
|
[signBtn.trailingAnchor constraintEqualToAnchor:contentView.trailingAnchor constant:-20],
|
|
[signBtn.widthAnchor constraintEqualToConstant:90],
|
|
[signBtn.heightAnchor constraintEqualToConstant:30],
|
|
|
|
[settingBtn.topAnchor constraintEqualToAnchor:contentView.topAnchor constant:-35],
|
|
[settingBtn.trailingAnchor constraintEqualToAnchor:contentView.trailingAnchor constant:-20],
|
|
[settingBtn.widthAnchor constraintEqualToConstant:24],
|
|
[settingBtn.heightAnchor constraintEqualToConstant:24]
|
|
]];
|
|
}
|
|
|
|
#pragma mark - 金币钻石
|
|
- (void)setupCoinDiamondInContentView:(UIView *)contentView {
|
|
NSArray *itemConfigs = @[
|
|
@{@"icon":@"hqz", @"text":@"6011.56"},
|
|
@{@"icon":@"hqz", @"text":@"0"}
|
|
];
|
|
|
|
UIView *containerView = [[UIView alloc] init];
|
|
containerView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[contentView addSubview:containerView];
|
|
|
|
for (int i = 0; i < itemConfigs.count; i++) {
|
|
NSDictionary *config = itemConfigs[i];
|
|
UIButton *btn = [self createInfoButtonWithConfig:config];
|
|
btn.tag = 100 + i;
|
|
[containerView addSubview:btn];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[btn.topAnchor constraintEqualToAnchor:containerView.topAnchor],
|
|
[btn.bottomAnchor constraintEqualToAnchor:containerView.bottomAnchor],
|
|
[btn.widthAnchor constraintEqualToAnchor:containerView.widthAnchor multiplier:0.5],
|
|
(i == 0) ? [btn.leadingAnchor constraintEqualToAnchor:containerView.leadingAnchor] : [btn.trailingAnchor constraintEqualToAnchor:containerView.trailingAnchor]
|
|
]];
|
|
}
|
|
|
|
UIView *verticalDivider = [self createVerticalDivider];
|
|
[containerView addSubview:verticalDivider];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[containerView.topAnchor constraintEqualToAnchor:contentView.subviews[1].bottomAnchor constant:20],
|
|
[containerView.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor],
|
|
[containerView.trailingAnchor constraintEqualToAnchor:contentView.trailingAnchor],
|
|
[containerView.heightAnchor constraintEqualToConstant:80],
|
|
|
|
[verticalDivider.centerXAnchor constraintEqualToAnchor:containerView.centerXAnchor],
|
|
[verticalDivider.topAnchor constraintEqualToAnchor:containerView.topAnchor constant:10],
|
|
[verticalDivider.bottomAnchor constraintEqualToAnchor:containerView.bottomAnchor constant:-10],
|
|
[verticalDivider.widthAnchor constraintEqualToConstant:0.5]
|
|
]];
|
|
}
|
|
|
|
#pragma mark - 设置列表
|
|
- (void)setupSettingListInContentView:(UIView *)contentView {
|
|
NSArray *rowTexts = @[
|
|
@"账号与安全",
|
|
@"服务期限",
|
|
@"行情设置",
|
|
@"通用设置",
|
|
@"金币记录",
|
|
@"分享奖励",
|
|
@"联系我们",
|
|
@"新版本更新",
|
|
@"意见反馈",
|
|
@"关于Homily Chart"
|
|
];
|
|
|
|
// 金币钻石容器
|
|
UIView *coinContainer = contentView.subviews.lastObject;
|
|
CGFloat topOffset = 0;
|
|
|
|
for (int i = 0; i < rowTexts.count; i++) {
|
|
UIView *itemView = [self createCommonRowWithText:rowTexts[i]];
|
|
[contentView addSubview:itemView];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[itemView.topAnchor constraintEqualToAnchor:coinContainer.bottomAnchor constant:topOffset + 20],
|
|
[itemView.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor],
|
|
[itemView.trailingAnchor constraintEqualToAnchor:contentView.trailingAnchor],
|
|
[itemView.heightAnchor constraintEqualToConstant:60]
|
|
]];
|
|
|
|
if (i < rowTexts.count - 1) {
|
|
UIView *divider = [self createDividerWithLeading:20];
|
|
[contentView addSubview:divider];
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[divider.topAnchor constraintEqualToAnchor:itemView.bottomAnchor],
|
|
[divider.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor constant:20],
|
|
[divider.trailingAnchor constraintEqualToAnchor:contentView.trailingAnchor],
|
|
[divider.heightAnchor constraintEqualToConstant:0.5]
|
|
]];
|
|
}
|
|
|
|
topOffset += 60;
|
|
}
|
|
|
|
self.lastSettingItem = contentView.subviews.lastObject;
|
|
}
|
|
|
|
#pragma mark - 退出登录
|
|
- (void)setupLogoutButtonInContentView:(UIView *)contentView {
|
|
UIButton *logoutBtn = [UIButton buttonWithType:UIButtonTypeSystem];
|
|
[logoutBtn setTitle:@"退出登录" forState:UIControlStateNormal];
|
|
[logoutBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
|
|
logoutBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
|
|
logoutBtn.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[logoutBtn addTarget:self action:@selector(logoutTapped) forControlEvents:UIControlEventTouchUpInside];
|
|
[contentView addSubview:logoutBtn];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[logoutBtn.topAnchor constraintEqualToAnchor:self.lastSettingItem.bottomAnchor constant:20],
|
|
[logoutBtn.centerXAnchor constraintEqualToAnchor:contentView.centerXAnchor],
|
|
[logoutBtn.widthAnchor constraintEqualToConstant:120],
|
|
[logoutBtn.heightAnchor constraintEqualToConstant:40],
|
|
|
|
[contentView.bottomAnchor constraintEqualToAnchor:logoutBtn.bottomAnchor constant:20]
|
|
]];
|
|
}
|
|
|
|
#pragma mark - 退出登录方法
|
|
- (void)logoutTapped {
|
|
ViewController *loginVC = [[ViewController alloc] init];
|
|
loginVC.hidesBottomBarWhenPushed = YES; // 隐藏TabBar
|
|
[self.navigationController pushViewController:loginVC animated:YES];
|
|
}
|
|
|
|
#pragma mark - 底部TabBar
|
|
- (void)setupTabBar {
|
|
NSArray *tabItems = @[
|
|
@{@"title":@"首页", @"icon":@"house.fill", @"selected":@NO},
|
|
@{@"title":@"行情", @"icon":@"chart.line.uptrend.xyaxis", @"selected":@NO},
|
|
@{@"title":@"自选", @"icon":@"plus", @"selected":@NO},
|
|
@{@"title":@"我的", @"icon":@"person", @"selected":@YES}
|
|
];
|
|
self.tabBar = [[CommonTabBar alloc] initWithTabItems:tabItems];
|
|
self.tabBar.delegate = self;
|
|
self.tabBar.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[self.view addSubview:self.tabBar];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[self.tabBar.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor],
|
|
[self.tabBar.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
|
|
[self.tabBar.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
|
|
[self.tabBar.heightAnchor constraintEqualToConstant:49]
|
|
]];
|
|
}
|
|
|
|
#pragma mark - 工具方法
|
|
- (UIButton *)createInfoButtonWithConfig:(NSDictionary *)config {
|
|
UIButtonConfiguration *btnConfig = [UIButtonConfiguration plainButtonConfiguration];
|
|
|
|
NSString *iconName = config[@"icon"];
|
|
UIImage *iconImage = [UIImage imageNamed:iconName];
|
|
|
|
if (!iconImage) {
|
|
UIImageSymbolConfiguration *symbolConfig = [UIImageSymbolConfiguration configurationWithPointSize:24 weight:UIFontWeightRegular];
|
|
iconImage = [UIImage systemImageNamed:@"dollarsign.circle" withConfiguration:symbolConfig];
|
|
} else {
|
|
UIGraphicsBeginImageContextWithOptions(CGSizeMake(40, 40), NO, 0);
|
|
[iconImage drawInRect:CGRectMake(0, 0, 40, 40)];
|
|
iconImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
UIGraphicsEndImageContext();
|
|
}
|
|
|
|
btnConfig.image = iconImage;
|
|
btnConfig.imagePlacement = NSDirectionalRectEdgeTop;
|
|
btnConfig.imagePadding = 15;
|
|
|
|
// 富文本吧
|
|
NSAttributedString *titleAttr = [[NSAttributedString alloc] initWithString:config[@"text"] attributes:@{
|
|
NSFontAttributeName: [UIFont systemFontOfSize:14],
|
|
NSForegroundColorAttributeName: [UIColor whiteColor]
|
|
}];
|
|
btnConfig.attributedTitle = titleAttr;
|
|
|
|
btnConfig.baseBackgroundColor = [UIColor clearColor];
|
|
btnConfig.baseForegroundColor = [UIColor whiteColor];
|
|
|
|
UIButton *btn = [UIButton buttonWithConfiguration:btnConfig primaryAction:nil];
|
|
btn.translatesAutoresizingMaskIntoConstraints = NO;
|
|
|
|
[btn addTarget:self action:@selector(infoButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
return btn;
|
|
}
|
|
|
|
- (void)infoButtonTapped:(UIButton *)sender {
|
|
if (sender.tag == 100) {
|
|
NSLog(@"金币按钮被点击");
|
|
} else if (sender.tag == 101) {
|
|
NSLog(@"钻石按钮被点击");
|
|
}
|
|
}
|
|
|
|
- (UIView *)createVerticalDivider {
|
|
UIView *divider = [[UIView alloc] init];
|
|
divider.backgroundColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:1];
|
|
divider.translatesAutoresizingMaskIntoConstraints = NO;
|
|
return divider;
|
|
}
|
|
|
|
- (UIImageView *)createImageViewWithImage:(NSString *)imageName contentMode:(UIViewContentMode)mode cornerRadius:(CGFloat)radius {
|
|
UIImageView *uiImageView = [[UIImageView alloc] init];
|
|
uiImageView.image = [UIImage imageNamed:imageName];
|
|
uiImageView.contentMode = mode;
|
|
uiImageView.layer.cornerRadius = radius;
|
|
uiImageView.clipsToBounds = YES;
|
|
uiImageView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
return uiImageView;
|
|
}
|
|
|
|
- (UILabel *)createLabelWithText:(NSString *)text fontSize:(CGFloat)size textColor:(UIColor *)color {
|
|
UILabel *label = [[UILabel alloc] init];
|
|
label.text = text;
|
|
label.font = [UIFont systemFontOfSize:size weight:UIFontWeightMedium];
|
|
label.textColor = color;
|
|
label.translatesAutoresizingMaskIntoConstraints = NO;
|
|
return label;
|
|
}
|
|
|
|
- (UIButton *)createButtonWithTitle:(NSString *)title bgColor:(UIColor *)bgColor cornerRadius:(CGFloat)radius {
|
|
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
|
|
[btn setTitle:title forState:UIControlStateNormal];
|
|
[btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
|
|
btn.backgroundColor = bgColor;
|
|
btn.layer.cornerRadius = radius;
|
|
btn.translatesAutoresizingMaskIntoConstraints = NO;
|
|
return btn;
|
|
}
|
|
|
|
- (UIView *)createDividerWithLeading:(CGFloat)leading {
|
|
UIView *divider = [[UIView alloc] init];
|
|
divider.backgroundColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:1];
|
|
divider.translatesAutoresizingMaskIntoConstraints = NO;
|
|
return divider;
|
|
}
|
|
|
|
- (UIView *)createCommonRowWithText:(NSString *)text {
|
|
UIView *rowView = [[UIView alloc] init];
|
|
rowView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
rowView.backgroundColor = [UIColor clearColor];
|
|
|
|
UIImageView *logoView = [self createImageViewWithImage:@"hqz"
|
|
contentMode:UIViewContentModeScaleAspectFit
|
|
cornerRadius:0];
|
|
logoView.tintColor = [UIColor blueColor];
|
|
[rowView addSubview:logoView];
|
|
|
|
UILabel *textLabel = [self createLabelWithText:text
|
|
fontSize:16
|
|
textColor:[UIColor whiteColor]];
|
|
[rowView addSubview:textLabel];
|
|
|
|
UIButton *arrowBtn = [UIButton buttonWithType:UIButtonTypeSystem];
|
|
[arrowBtn setImage:[UIImage systemImageNamed:@"chevron.right"] forState:UIControlStateNormal];
|
|
[arrowBtn setTintColor:[UIColor lightGrayColor]];
|
|
arrowBtn.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[rowView addSubview:arrowBtn];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
// logo左侧固定
|
|
[logoView.centerYAnchor constraintEqualToAnchor:rowView.centerYAnchor],
|
|
[logoView.leadingAnchor constraintEqualToAnchor:rowView.leadingAnchor constant:20],
|
|
[logoView.widthAnchor constraintEqualToConstant:24],
|
|
[logoView.heightAnchor constraintEqualToConstant:24],
|
|
|
|
// 文字 logo右侧
|
|
[textLabel.centerYAnchor constraintEqualToAnchor:logoView.centerYAnchor],
|
|
[textLabel.leadingAnchor constraintEqualToAnchor:logoView.trailingAnchor constant:15],
|
|
|
|
// 箭头 右侧固定
|
|
[arrowBtn.centerYAnchor constraintEqualToAnchor:logoView.centerYAnchor],
|
|
[arrowBtn.trailingAnchor constraintEqualToAnchor:rowView.trailingAnchor constant:-20]
|
|
]];
|
|
|
|
return rowView;
|
|
}
|
|
|
|
#pragma mark - TabBar
|
|
- (void) pushHome {
|
|
HomeViewController *homeViewController = [[HomeViewController alloc] init];
|
|
[self.navigationController pushViewController:homeViewController animated:YES];
|
|
}
|
|
|
|
- (void) pushQuotation {
|
|
QuotationViewController *quotationViewController = [[QuotationViewController alloc] init];
|
|
[self.navigationController pushViewController:quotationViewController animated:YES];
|
|
}
|
|
|
|
- (void)tabBarDidSelectIndex:(NSInteger)index {
|
|
if (index == 3) {
|
|
|
|
} else if (index == 0) {
|
|
[self pushHome];
|
|
} else if (index == 1) {
|
|
[self pushQuotation];
|
|
} else if (index == 2) {
|
|
// 自选
|
|
}
|
|
}
|
|
|
|
@end
|