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.
585 lines
29 KiB
585 lines
29 KiB
//
|
|
// MLXYViewController.m
|
|
// HC
|
|
//
|
|
// Created by huilinLi on 2025/11/26.
|
|
//
|
|
|
|
#import "MLXYViewController.h"
|
|
#import "ChartViewController.h"
|
|
|
|
#pragma mark - cell们
|
|
static NSString *const stockCell = @"StockCell";// 股票cell
|
|
static NSString *const permCell = @"PermCell";// 接口cell
|
|
|
|
@interface MLXYViewController () <UITableViewDataSource, UITableViewDelegate>
|
|
|
|
#pragma mark - Config
|
|
@property (nonatomic, strong) UIButtonConfiguration *buttonConfig;
|
|
@property (nonatomic, strong) NSArray *sectorDataConfig;
|
|
@property (nonatomic, strong) NSMutableArray *permissionDataList;
|
|
|
|
#pragma mark - 滚动相关
|
|
@property (nonatomic, strong) UIScrollView *globalScrollView;
|
|
@property (nonatomic, strong) UIView *scrollContentView;
|
|
@property (nonatomic, strong) UIButton *mlxyButton;
|
|
|
|
#pragma mark - 大盘
|
|
@property (nonatomic, strong) UILabel *marketTitleLabel;
|
|
@property (nonatomic, strong) UIView *marketView;
|
|
@property (nonatomic, strong) UILabel *marketLine1;
|
|
@property (nonatomic, strong) UILabel *marketLine2;
|
|
@property (nonatomic, strong) UILabel *marketLine3;
|
|
|
|
#pragma mark - 板块
|
|
@property (nonatomic, strong) UILabel *sectorTitleLabel;
|
|
@property (nonatomic, strong) UIButton *sectorBtn;
|
|
@property (nonatomic, strong) UIView *sectorCard1;
|
|
@property (nonatomic, strong) UIView *sectorCard2;
|
|
@property (nonatomic, strong) UIView *sectorCard3;
|
|
|
|
#pragma mark - 股票容器
|
|
@property (nonatomic, strong) UIView *stockContainer;
|
|
@property (nonatomic, strong) UIView *stockHeaderView;
|
|
@property (nonatomic, strong) UITableView *stockTableView;
|
|
|
|
#pragma mark - 接口容器
|
|
@property (nonatomic, strong) UIView *stockContainer1;
|
|
@property (nonatomic, strong) UILabel *stockLabel1;
|
|
@property (nonatomic, strong) UIView *permissionHeaderView;
|
|
@property (nonatomic, strong) UITableView *permissionTableView;
|
|
|
|
@end
|
|
|
|
@implementation MLXYViewController
|
|
|
|
#pragma mark - viewDidLoad
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
self.view.backgroundColor = [UIColor blackColor];
|
|
|
|
[self setupData];
|
|
|
|
[self setupGlobalScrollView];
|
|
[self setupSubviews];
|
|
|
|
[self marketViewClick];
|
|
|
|
[self setupConstraints];
|
|
|
|
[self fetchPermissionData];
|
|
}
|
|
|
|
#pragma mark - 数据
|
|
- (void)setupData {
|
|
_permissionDataList = [NSMutableArray array];
|
|
|
|
_sectorDataConfig = @[
|
|
@{@"name":@"Health", @"value1":@"1099.683", @"value2":@"27.236",@"value3":@"2.270%"},
|
|
@{@"name":@"Others", @"value1":@"2083.783", @"value2":@"0.000",@"value3":@"0.000%"},
|
|
@{@"name":@"HLKLI", @"value1":@"987.895", @"value2":@"-1.854",@"value3":@"-0.230%"}
|
|
];
|
|
|
|
UIButtonConfiguration *config = [UIButtonConfiguration plainButtonConfiguration];
|
|
config.title = @"更多";
|
|
config.attributedTitle = [[NSAttributedString alloc] initWithString:@"更多" attributes:@{
|
|
NSFontAttributeName: [UIFont systemFontOfSize:14],
|
|
NSForegroundColorAttributeName: [UIColor lightGrayColor]// 文字颜色
|
|
}];
|
|
config.image = [UIImage systemImageNamed:@"chevron.right"];
|
|
config.imagePlacement = NSDirectionalRectEdgeTrailing;
|
|
config.imagePadding = 1;
|
|
config.baseForegroundColor = [UIColor lightGrayColor];// 按钮文字和模板都会继承这个颜色
|
|
_buttonConfig = config;
|
|
}
|
|
|
|
#pragma mark - 发请求
|
|
|
|
- (void)fetchPermissionData {
|
|
NSString *urlString = @"https://hwjb.homilychart.com/dev/admin/permission/getPermission";
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
|
|
request.HTTPMethod = @"POST";
|
|
|
|
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
|
NSString *token = @"eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIwMTQ0ZDE4MWQ3NDI0ZjljYjk1OTI0Y2RiZWQzZTlmYSIsInN1YiI6IntcImlkXCI6MTAwMDAxMyxcImFkbWluTmFtZVwiOlwi5p2O5oWn55Cz5ryU56S65py6XCIsXCJhY2NvdW50XCI6XCI5MDA0NzY4MVwiLFwicGFzc3dvcmRcIjpcIiQyYSQxMCRzSXVXMFNSMllEZFIyMGxxZnVRRXBlbDdHU2NTVmRqb1lDaXNrSmpTU0suNE5hbmN5NkUyLlwiLFwibWFjaGluZUlkXCI6XCIyMDAzMDQwMSxGQzM2RDYzOEZGM0FcIixcIm1hY2hpbmVJZHNcIjpudWxsLFwiYWRtaW5TdGF0dXNcIjoxLFwibWFya2V0XCI6bnVsbCxcIm1hcmtldHNcIjpcIuaAu-mDqFwiLFwicm9sZUtleVwiOm51bGwsXCJwb3N0aXRvblwiOlwi56CU5Y-RXCIsXCJyZW1hcmtcIjpcIuWRmOW3pVwiLFwiY3JlYXRlVGltZVwiOlwiMjAyNS0wOC0xMCAxNDozNDowOVwiLFwidXBkYXRlVGltZVwiOlwiMjAyNS0xMS0yMSAxNzo1NDo0MVwiLFwicm9sZUlkXCI6MixcInVzZXJuYW1lXCI6XCI5MDA0NzY4MVwifSIsImlzcyI6InNnIiwiaWF0IjoxNzY0OTE1NzQ5LCJleHAiOjE3NjUwMDIxNDl9.5O__C0lpO3CBHMVPOjiUsLD1Cp733aBZCcDmpkfcXSc";
|
|
[request setValue:token forHTTPHeaderField:@"token"];
|
|
|
|
NSDictionary *params = @{
|
|
@"pageNum": @1,
|
|
@"pageSize": @10,
|
|
@"permission": @{ @"account": @"", @"market": @"", @"postiton": @"" }
|
|
};
|
|
|
|
// 参数转json
|
|
NSError *error;
|
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error];
|
|
if (!error) {request.HTTPBody = jsonData;
|
|
}else{
|
|
NSLog(@"参数转json失败:%@",error);
|
|
return;
|
|
}
|
|
|
|
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
|
if (error) {
|
|
NSLog(@"请求失败: %@", error);
|
|
return;
|
|
}
|
|
if (data) {
|
|
NSError *jsonError;
|
|
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
|
|
if (!jsonError && [json[@"code"] integerValue] == 200) {
|
|
NSArray *list = json[@"data"][@"list"];
|
|
[self.permissionDataList removeAllObjects];
|
|
[self.permissionDataList addObjectsFromArray:list];
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[self.permissionTableView reloadData];
|
|
});
|
|
}
|
|
}
|
|
}];
|
|
[task resume];
|
|
}
|
|
|
|
#pragma mark - 子视图们
|
|
- (void)setupGlobalScrollView {
|
|
_globalScrollView = [[UIScrollView alloc] init];
|
|
_globalScrollView.backgroundColor = [UIColor blackColor];
|
|
_globalScrollView.showsVerticalScrollIndicator = YES;
|
|
_globalScrollView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[self.view addSubview:_globalScrollView];
|
|
|
|
_scrollContentView = [[UIView alloc] init];
|
|
_scrollContentView.backgroundColor = [UIColor blackColor];
|
|
_scrollContentView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_globalScrollView addSubview:_scrollContentView];
|
|
}
|
|
|
|
- (void)setupSubviews {
|
|
_mlxyButton = [UIButton buttonWithType:UIButtonTypeSystem];
|
|
[_mlxyButton setTitle:@"马来西亚" forState:UIControlStateNormal];
|
|
[_mlxyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
[_mlxyButton setBackgroundColor:[UIColor blueColor]];
|
|
_mlxyButton.layer.cornerRadius = 15;
|
|
_mlxyButton.titleLabel.font = [UIFont systemFontOfSize:14];
|
|
_mlxyButton.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_scrollContentView addSubview:_mlxyButton];
|
|
|
|
// 大盘
|
|
[self setupMarketUI];
|
|
// 板块
|
|
[self setupSectorUI];
|
|
// 股票
|
|
[self setupStockListUI];
|
|
// 接口
|
|
[self setupPermissionUI];
|
|
}
|
|
|
|
- (void)setupMarketUI {
|
|
_marketTitleLabel = [self createTitleLabel:@"大盘指数"];
|
|
[_scrollContentView addSubview:_marketTitleLabel];
|
|
|
|
_marketView = [[UIView alloc] init];
|
|
_marketView.backgroundColor = [UIColor greenColor];
|
|
_marketView.layer.cornerRadius = 8;
|
|
_marketView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_scrollContentView addSubview:_marketView];
|
|
|
|
_marketLine1 = [self createMarketLabel:@"富时马来西亚KLCI" fontSize:12 isBold:YES];
|
|
_marketLine2 = [self createMarketLabel:@"1624.500" fontSize:17 isBold:YES];
|
|
_marketLine3 = [self createMarketLabel:@"12.760 0.792%" fontSize:12 isBold:YES];
|
|
|
|
[_marketView addSubview:_marketLine1];
|
|
[_marketView addSubview:_marketLine2];
|
|
[_marketView addSubview:_marketLine3];
|
|
}
|
|
|
|
- (void)setupSectorUI {
|
|
_sectorTitleLabel = [self createTitleLabel:@"板块"];
|
|
[_scrollContentView addSubview:_sectorTitleLabel];
|
|
|
|
_sectorBtn = [UIButton buttonWithConfiguration:self.buttonConfig primaryAction:nil];
|
|
_sectorBtn.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_scrollContentView addSubview:_sectorBtn];
|
|
|
|
_sectorCard1 = [self createSectorCardWithData:self.sectorDataConfig[0]];
|
|
_sectorCard2 = [self createSectorCardWithData:self.sectorDataConfig[1]];
|
|
_sectorCard3 = [self createSectorCardWithData:self.sectorDataConfig[2]];
|
|
|
|
[_scrollContentView addSubview:_sectorCard1];
|
|
[_scrollContentView addSubview:_sectorCard2];
|
|
[_scrollContentView addSubview:_sectorCard3];
|
|
}
|
|
|
|
- (void)setupStockListUI {
|
|
_stockContainer = [[UIView alloc] init];
|
|
_stockContainer.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_scrollContentView addSubview:_stockContainer];
|
|
|
|
UILabel *title = [self createTitleLabel:@"股票"];
|
|
[_stockContainer addSubview:title];
|
|
|
|
UIButton *btn = [UIButton buttonWithConfiguration:self.buttonConfig primaryAction:nil];
|
|
btn.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_stockContainer addSubview:btn];
|
|
|
|
_stockHeaderView = [[UIView alloc] init];
|
|
_stockHeaderView.backgroundColor = [UIColor blackColor];
|
|
_stockHeaderView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_stockContainer addSubview:_stockHeaderView];
|
|
|
|
[self setupHeaderLabelsForView:_stockHeaderView titles:@[@"名称", @"最新", @"涨幅"] isWhite:NO];
|
|
|
|
_stockTableView = [[UITableView alloc] init];
|
|
_stockTableView.backgroundColor = [UIColor blackColor];
|
|
_stockTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
_stockTableView.delegate = self;
|
|
_stockTableView.dataSource = self;
|
|
_stockTableView.scrollEnabled = NO;
|
|
[_stockTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:stockCell];
|
|
_stockTableView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_stockContainer addSubview:_stockTableView];
|
|
}
|
|
|
|
- (void)setupPermissionUI {
|
|
_stockContainer1 = [[UIView alloc] init];
|
|
_stockContainer1.backgroundColor = [UIColor whiteColor];
|
|
_stockContainer1.layer.cornerRadius = 8;
|
|
_stockContainer1.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_scrollContentView addSubview:_stockContainer1];
|
|
|
|
_stockLabel1 = [[UILabel alloc] init];
|
|
_stockLabel1.text = @"真数据!";
|
|
_stockLabel1.textColor = [UIColor blackColor];
|
|
_stockLabel1.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
|
|
_stockLabel1.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_stockContainer1 addSubview:_stockLabel1];
|
|
|
|
_permissionHeaderView = [[UIView alloc] init];
|
|
_permissionHeaderView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
|
|
_permissionHeaderView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_stockContainer1 addSubview:_permissionHeaderView];
|
|
|
|
[self setupHeaderLabelsForView:_permissionHeaderView titles:@[@"Name", @"Account", @"Market", @"Position"] isWhite:YES];
|
|
|
|
_permissionTableView = [[UITableView alloc] init];
|
|
_permissionTableView.backgroundColor = [UIColor whiteColor];
|
|
_permissionTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
|
|
_permissionTableView.delegate = self;
|
|
_permissionTableView.dataSource = self;
|
|
_permissionTableView.scrollEnabled = NO;
|
|
[_permissionTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:permCell];
|
|
_permissionTableView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_stockContainer1 addSubview:_permissionTableView];
|
|
}
|
|
|
|
#pragma mark - 小工具
|
|
- (UILabel *)createTitleLabel:(NSString *)text {
|
|
UILabel *label = [[UILabel alloc] init];
|
|
label.text = text;
|
|
label.textColor = [UIColor whiteColor];
|
|
label.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
|
|
label.translatesAutoresizingMaskIntoConstraints = NO;
|
|
return label;
|
|
}
|
|
|
|
- (UILabel *)createMarketLabel:(NSString *)text fontSize:(CGFloat)size isBold:(BOOL)isBold {
|
|
UILabel *label = [[UILabel alloc] init];
|
|
label.text = text;
|
|
label.textColor = [UIColor whiteColor];
|
|
label.font = isBold ? [UIFont boldSystemFontOfSize:size] : [UIFont systemFontOfSize:size];
|
|
label.textAlignment = NSTextAlignmentCenter;
|
|
label.translatesAutoresizingMaskIntoConstraints = NO;
|
|
return label;
|
|
}
|
|
|
|
- (void)setupHeaderLabelsForView:(UIView *)view titles:(NSArray *)titles isWhite:(BOOL)isWhite {
|
|
CGFloat multiplier = 1.0 / titles.count;
|
|
for (NSInteger i = 0; i < titles.count; i++) {
|
|
UILabel *label = [[UILabel alloc] init];
|
|
label.text = titles[i];
|
|
label.textColor = isWhite ? [UIColor darkGrayColor] : [UIColor lightGrayColor];
|
|
label.font = isWhite ? [UIFont boldSystemFontOfSize:12] : [UIFont systemFontOfSize:12];
|
|
label.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[view addSubview:label];
|
|
|
|
if (isWhite) {
|
|
// 等分
|
|
label.textAlignment = NSTextAlignmentCenter;
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[label.topAnchor constraintEqualToAnchor:view.topAnchor],
|
|
[label.bottomAnchor constraintEqualToAnchor:view.bottomAnchor],
|
|
[label.widthAnchor constraintEqualToAnchor:view.widthAnchor multiplier:multiplier],
|
|
(i == 0) ? [label.leadingAnchor constraintEqualToAnchor:view.leadingAnchor] : [label.leadingAnchor constraintEqualToAnchor:view.subviews[i-1].trailingAnchor]
|
|
]];
|
|
} else {
|
|
// 股票表头
|
|
label.textAlignment = (i == 0) ? NSTextAlignmentLeft : NSTextAlignmentRight;
|
|
[label.centerYAnchor constraintEqualToAnchor:view.centerYAnchor].active = YES;
|
|
if (i == 0) {
|
|
[label.leadingAnchor constraintEqualToAnchor:view.leadingAnchor constant:15].active = YES;
|
|
} else if (i == 1) {
|
|
[label.widthAnchor constraintEqualToConstant:60].active = YES;
|
|
[label.trailingAnchor constraintEqualToAnchor:view.trailingAnchor constant:-110].active = YES;
|
|
} else {
|
|
[label.widthAnchor constraintEqualToConstant:80].active = YES;
|
|
[label.trailingAnchor constraintEqualToAnchor:view.trailingAnchor constant:-30].active = YES;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
- (UIView *)createSectorCardWithData:(NSDictionary *)data {
|
|
UIView *card = [[UIView alloc] init];
|
|
card.backgroundColor = [UIColor darkGrayColor];
|
|
card.layer.cornerRadius = 8;
|
|
card.translatesAutoresizingMaskIntoConstraints = NO;
|
|
|
|
UILabel *nameLabel = [self createCardLabel:data[@"name"] color:[UIColor whiteColor] size:14 bold:NO];
|
|
UILabel *val1Label = [self createCardLabel:data[@"value1"] color:[UIColor greenColor] size:16 bold:YES];
|
|
UILabel *val2Label = [self createCardLabel:data[@"value2"] color:[UIColor greenColor] size:12 bold:NO];
|
|
UILabel *val3Label = [self createCardLabel:data[@"value3"] color:[UIColor greenColor] size:12 bold:NO];
|
|
|
|
[card addSubview:nameLabel];
|
|
[card addSubview:val1Label];
|
|
[card addSubview:val2Label];
|
|
[card addSubview:val3Label];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[nameLabel.topAnchor constraintEqualToAnchor:card.topAnchor constant:7],
|
|
[nameLabel.leadingAnchor constraintEqualToAnchor:card.leadingAnchor constant:10],
|
|
[val1Label.topAnchor constraintEqualToAnchor:nameLabel.bottomAnchor constant:10],
|
|
[val1Label.leadingAnchor constraintEqualToAnchor:card.leadingAnchor constant:10],
|
|
[val2Label.topAnchor constraintEqualToAnchor:val1Label.bottomAnchor constant:7],
|
|
[val2Label.leadingAnchor constraintEqualToAnchor:card.leadingAnchor constant:10],
|
|
[val3Label.topAnchor constraintEqualToAnchor:val2Label.bottomAnchor constant:6],
|
|
[val3Label.leadingAnchor constraintEqualToAnchor:card.leadingAnchor constant:10]
|
|
]];
|
|
return card;
|
|
}
|
|
|
|
- (UILabel *)createCardLabel:(NSString *)text color:(UIColor *)color size:(CGFloat)size bold:(BOOL)bold {
|
|
UILabel *label = [[UILabel alloc] init];
|
|
label.text = text;
|
|
label.textColor = color;
|
|
label.font = bold ? [UIFont boldSystemFontOfSize:size] : [UIFont systemFontOfSize:size];
|
|
label.translatesAutoresizingMaskIntoConstraints = NO;
|
|
return label;
|
|
}
|
|
|
|
#pragma mark - 约束们
|
|
|
|
- (void)setupConstraints {
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[_globalScrollView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
|
|
[_globalScrollView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
|
|
[_globalScrollView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor],
|
|
[_globalScrollView.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor],
|
|
|
|
[_scrollContentView.leadingAnchor constraintEqualToAnchor:_globalScrollView.leadingAnchor],
|
|
[_scrollContentView.trailingAnchor constraintEqualToAnchor:_globalScrollView.trailingAnchor],
|
|
[_scrollContentView.topAnchor constraintEqualToAnchor:_globalScrollView.topAnchor],
|
|
[_scrollContentView.bottomAnchor constraintEqualToAnchor:_globalScrollView.bottomAnchor],
|
|
[_scrollContentView.widthAnchor constraintEqualToAnchor:self.view.widthAnchor]
|
|
]];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[_mlxyButton.topAnchor constraintEqualToAnchor:_scrollContentView.topAnchor constant:15],
|
|
[_mlxyButton.leadingAnchor constraintEqualToAnchor:_scrollContentView.leadingAnchor constant:15],
|
|
[_mlxyButton.widthAnchor constraintEqualToConstant:90],
|
|
[_mlxyButton.heightAnchor constraintEqualToConstant:30]
|
|
]];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[_marketTitleLabel.topAnchor constraintEqualToAnchor:_mlxyButton.bottomAnchor constant:10],
|
|
[_marketTitleLabel.leadingAnchor constraintEqualToAnchor:_scrollContentView.leadingAnchor constant:15],
|
|
|
|
[_marketView.topAnchor constraintEqualToAnchor:_marketTitleLabel.bottomAnchor constant:10],
|
|
[_marketView.leadingAnchor constraintEqualToAnchor:_scrollContentView.leadingAnchor constant:15],
|
|
[_marketView.widthAnchor constraintEqualToAnchor:_scrollContentView.widthAnchor multiplier:0.3],
|
|
[_marketView.heightAnchor constraintEqualToConstant:100],
|
|
|
|
[_marketLine1.topAnchor constraintEqualToAnchor:_marketView.topAnchor constant:10],
|
|
[_marketLine1.centerXAnchor constraintEqualToAnchor:_marketView.centerXAnchor],
|
|
[_marketLine2.topAnchor constraintEqualToAnchor:_marketLine1.bottomAnchor constant:15],
|
|
[_marketLine2.centerXAnchor constraintEqualToAnchor:_marketView.centerXAnchor],
|
|
[_marketLine3.topAnchor constraintEqualToAnchor:_marketLine2.bottomAnchor constant:12],
|
|
[_marketLine3.centerXAnchor constraintEqualToAnchor:_marketView.centerXAnchor]
|
|
]];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[_sectorTitleLabel.topAnchor constraintEqualToAnchor:_marketView.bottomAnchor constant:20],
|
|
[_sectorTitleLabel.leadingAnchor constraintEqualToAnchor:_scrollContentView.leadingAnchor constant:15],
|
|
|
|
[_sectorBtn.centerYAnchor constraintEqualToAnchor:_sectorTitleLabel.centerYAnchor],
|
|
[_sectorBtn.trailingAnchor constraintEqualToAnchor:_scrollContentView.trailingAnchor constant:-15],
|
|
|
|
[_sectorCard1.topAnchor constraintEqualToAnchor:_sectorTitleLabel.bottomAnchor constant:10],
|
|
[_sectorCard1.leadingAnchor constraintEqualToAnchor:_scrollContentView.leadingAnchor constant:8],
|
|
[_sectorCard1.widthAnchor constraintEqualToAnchor:_scrollContentView.widthAnchor multiplier:0.3],
|
|
[_sectorCard1.heightAnchor constraintEqualToConstant:100],
|
|
|
|
[_sectorCard2.topAnchor constraintEqualToAnchor:_sectorCard1.topAnchor],
|
|
[_sectorCard2.leadingAnchor constraintEqualToAnchor:_sectorCard1.trailingAnchor constant:8],
|
|
[_sectorCard2.widthAnchor constraintEqualToAnchor:_sectorCard1.widthAnchor],
|
|
[_sectorCard2.heightAnchor constraintEqualToAnchor:_sectorCard1.heightAnchor],
|
|
|
|
[_sectorCard3.topAnchor constraintEqualToAnchor:_sectorCard1.topAnchor],
|
|
[_sectorCard3.leadingAnchor constraintEqualToAnchor:_sectorCard2.trailingAnchor constant:8],
|
|
[_sectorCard3.trailingAnchor constraintEqualToAnchor:_scrollContentView.trailingAnchor constant:-16],
|
|
[_sectorCard3.heightAnchor constraintEqualToAnchor:_sectorCard1.heightAnchor]
|
|
]];
|
|
|
|
UILabel *stockTitle = _stockContainer.subviews[0];
|
|
UIButton *stockBtn = _stockContainer.subviews[1];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[_stockContainer.topAnchor constraintEqualToAnchor:_sectorCard1.bottomAnchor constant:20],
|
|
[_stockContainer.leadingAnchor constraintEqualToAnchor:_scrollContentView.leadingAnchor],
|
|
[_stockContainer.trailingAnchor constraintEqualToAnchor:_scrollContentView.trailingAnchor],
|
|
[_stockContainer.bottomAnchor constraintEqualToAnchor:_stockTableView.bottomAnchor constant:10],
|
|
|
|
[stockTitle.topAnchor constraintEqualToAnchor:_stockContainer.topAnchor constant:15],
|
|
[stockTitle.leadingAnchor constraintEqualToAnchor:_stockContainer.leadingAnchor constant:15],
|
|
[stockBtn.centerYAnchor constraintEqualToAnchor:stockTitle.centerYAnchor],
|
|
[stockBtn.trailingAnchor constraintEqualToAnchor:_stockContainer.trailingAnchor constant:-15],
|
|
|
|
[_stockHeaderView.topAnchor constraintEqualToAnchor:stockTitle.bottomAnchor constant:10],
|
|
[_stockHeaderView.leadingAnchor constraintEqualToAnchor:_stockContainer.leadingAnchor],
|
|
[_stockHeaderView.trailingAnchor constraintEqualToAnchor:_stockContainer.trailingAnchor],
|
|
[_stockHeaderView.heightAnchor constraintEqualToConstant:30],
|
|
|
|
[_stockTableView.topAnchor constraintEqualToAnchor:_stockHeaderView.bottomAnchor],
|
|
[_stockTableView.leadingAnchor constraintEqualToAnchor:_stockContainer.leadingAnchor],
|
|
[_stockTableView.trailingAnchor constraintEqualToAnchor:_stockContainer.trailingAnchor],
|
|
[_stockTableView.heightAnchor constraintEqualToConstant:240]
|
|
]];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[_stockContainer1.topAnchor constraintEqualToAnchor:_stockContainer.bottomAnchor constant:20],
|
|
[_stockContainer1.leadingAnchor constraintEqualToAnchor:_scrollContentView.leadingAnchor constant:15],
|
|
[_stockContainer1.trailingAnchor constraintEqualToAnchor:_scrollContentView.trailingAnchor constant:-15],
|
|
[_stockContainer1.heightAnchor constraintEqualToConstant:290], // Height approximation
|
|
[_stockContainer1.bottomAnchor constraintEqualToAnchor:_scrollContentView.bottomAnchor constant:-20],
|
|
|
|
[_stockLabel1.topAnchor constraintEqualToAnchor:_stockContainer1.topAnchor constant:10],
|
|
[_stockLabel1.leadingAnchor constraintEqualToAnchor:_stockContainer1.leadingAnchor constant:15],
|
|
|
|
[_permissionHeaderView.topAnchor constraintEqualToAnchor:_stockLabel1.bottomAnchor constant:10],
|
|
[_permissionHeaderView.leadingAnchor constraintEqualToAnchor:_stockContainer1.leadingAnchor],
|
|
[_permissionHeaderView.trailingAnchor constraintEqualToAnchor:_stockContainer1.trailingAnchor],
|
|
[_permissionHeaderView.heightAnchor constraintEqualToConstant:30],
|
|
|
|
[_permissionTableView.topAnchor constraintEqualToAnchor:_permissionHeaderView.bottomAnchor],
|
|
[_permissionTableView.leadingAnchor constraintEqualToAnchor:_stockContainer1.leadingAnchor],
|
|
[_permissionTableView.trailingAnchor constraintEqualToAnchor:_stockContainer1.trailingAnchor],
|
|
[_permissionTableView.bottomAnchor constraintEqualToAnchor:_stockContainer1.bottomAnchor constant:-5]
|
|
]];
|
|
}
|
|
|
|
#pragma mark - 跳转k线
|
|
-(void)marketViewClick{
|
|
_marketView.userInteractionEnabled = YES;
|
|
UITapGestureRecognizer *click = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(marketViewPush)];
|
|
[_marketView addGestureRecognizer:click];
|
|
}
|
|
|
|
-(void)marketViewPush{
|
|
ChartViewController *chartViewController = [[ChartViewController alloc] init];
|
|
[self.navigationController pushViewController:chartViewController animated:YES];
|
|
}
|
|
|
|
#pragma mark - 哦哦哦哦哦
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
if (tableView == _stockTableView) return 4;// 股票表4行
|
|
if (tableView == _permissionTableView) return MIN(self.permissionDataList.count, 5);// 接口最多5行
|
|
return 0;
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
return (tableView == _stockTableView) ? 60 : 44;// 行高
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (tableView == _stockTableView) {
|
|
return [self stockCellForIndexPath:indexPath];
|
|
} else {
|
|
return [self permissionCellForIndexPath:indexPath];
|
|
}
|
|
}
|
|
|
|
// 股票Cell
|
|
- (UITableViewCell *)stockCellForIndexPath:(NSIndexPath *)indexPath {
|
|
UITableViewCell *cell = [_stockTableView dequeueReusableCellWithIdentifier:stockCell forIndexPath:indexPath];
|
|
cell.backgroundColor = [UIColor blackColor];
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
[cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
|
|
|
|
NSArray *stocks = @[
|
|
@{@"name":@"PEGASUS HEIGHTS BERHAD", @"code":@"4464", @"price":@"0.010", @"value2":@"100.000%"},
|
|
@{@"name":@"SMTRACK BERHAD", @"code":@"0169", @"price":@"0.010", @"value2":@"100.000%"},
|
|
@{@"name":@"TXCD BERHAD - ICPS 2020/2030", @"code":@"7145PA", @"price":@"0.020", @"value2":@"33.333%"},
|
|
@{@"name":@"DNONCE TECHNOLOGY BHD", @"code":@"7114", @"price":@"0.040", @"value2":@"33.333%"}
|
|
];
|
|
NSDictionary *data = stocks[indexPath.row];
|
|
|
|
UILabel *name = [self createCardLabel:data[@"name"] color:[UIColor whiteColor] size:14 bold:NO];
|
|
name.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
UILabel *code = [self createCardLabel:data[@"code"] color:[UIColor lightGrayColor] size:12 bold:NO];
|
|
UILabel *price = [self createCardLabel:data[@"price"] color:[UIColor greenColor] size:14 bold:NO];
|
|
price.textAlignment = NSTextAlignmentRight;
|
|
UILabel *val2 = [self createCardLabel:data[@"value2"] color:[UIColor greenColor] size:14 bold:NO];
|
|
val2.textAlignment = NSTextAlignmentRight;
|
|
|
|
[cell.contentView addSubview:name];
|
|
[cell.contentView addSubview:code];
|
|
[cell.contentView addSubview:price];
|
|
[cell.contentView addSubview:val2];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[name.leadingAnchor constraintEqualToAnchor:cell.contentView.leadingAnchor constant:15],
|
|
[name.topAnchor constraintEqualToAnchor:cell.contentView.topAnchor constant:10],
|
|
[name.trailingAnchor constraintLessThanOrEqualToAnchor:price.leadingAnchor constant:-10],
|
|
|
|
[code.leadingAnchor constraintEqualToAnchor:cell.contentView.leadingAnchor constant:15],
|
|
[code.topAnchor constraintEqualToAnchor:name.bottomAnchor constant:5],
|
|
|
|
[price.widthAnchor constraintEqualToConstant:60],
|
|
[price.trailingAnchor constraintEqualToAnchor:val2.leadingAnchor constant:-10],
|
|
[price.centerYAnchor constraintEqualToAnchor:cell.contentView.centerYAnchor],
|
|
|
|
[val2.widthAnchor constraintEqualToConstant:80],
|
|
[val2.trailingAnchor constraintEqualToAnchor:cell.contentView.trailingAnchor constant:-15],
|
|
[val2.centerYAnchor constraintEqualToAnchor:cell.contentView.centerYAnchor]
|
|
]];
|
|
return cell;
|
|
}
|
|
|
|
// 接口Cell
|
|
- (UITableViewCell *)permissionCellForIndexPath:(NSIndexPath *)indexPath {
|
|
UITableViewCell *cell = [_permissionTableView dequeueReusableCellWithIdentifier:permCell forIndexPath:indexPath];
|
|
cell.backgroundColor = [UIColor whiteColor];
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
[cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
|
|
|
|
NSDictionary *item = self.permissionDataList[indexPath.row];
|
|
NSArray *values = @[item[@"name"] ?: @"-", item[@"account"] ?: @"-", item[@"market"] ?: @"-", item[@"postiton"] ?: @"-"];
|
|
|
|
for (NSInteger i = 0; i < values.count; i++) {
|
|
UILabel *label = [self createCardLabel:[NSString stringWithFormat:@"%@", values[i]] color:[UIColor blackColor] size:11 bold:NO];
|
|
label.textAlignment = NSTextAlignmentCenter;
|
|
label.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
[cell.contentView addSubview:label];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[label.topAnchor constraintEqualToAnchor:cell.contentView.topAnchor],
|
|
[label.bottomAnchor constraintEqualToAnchor:cell.contentView.bottomAnchor],
|
|
[label.widthAnchor constraintEqualToAnchor:cell.contentView.widthAnchor multiplier:0.25],
|
|
(i == 0) ? [label.leadingAnchor constraintEqualToAnchor:cell.contentView.leadingAnchor] : [label.leadingAnchor constraintEqualToAnchor:cell.contentView.subviews[i-1].trailingAnchor]
|
|
]];
|
|
}
|
|
return cell;
|
|
}
|
|
|
|
@end
|