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.
442 lines
22 KiB
442 lines
22 KiB
//
|
|
// MLXYViewController.m
|
|
// HC
|
|
//
|
|
// Created by huilinLi on 2025/11/26.
|
|
//
|
|
#import "MLXYViewController.h"
|
|
#import "ChartViewController.h"
|
|
|
|
@interface MLXYViewController () <UITableViewDataSource, UITableViewDelegate>
|
|
@property (nonatomic, strong) UIButton *mlxyButton;
|
|
// 大盘指数
|
|
@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;
|
|
// 板块
|
|
@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;
|
|
// 股票
|
|
@property (nonatomic, strong) UIView *stockContainer;
|
|
@property (nonatomic, strong) UITableView *stockTableView;
|
|
// 股票表头
|
|
@property (nonatomic, strong) UIView *stockHeaderView;
|
|
// 按钮配置
|
|
@property (nonatomic, strong) UIButtonConfiguration *buttonConfig;
|
|
// 板块数据配置
|
|
@property (nonatomic, strong) NSArray *sectorDataConfig;
|
|
@end
|
|
|
|
@implementation MLXYViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
self.view.backgroundColor = [UIColor blackColor];
|
|
|
|
[self setupButtonConfig];
|
|
[self setupSectorDataConfig];
|
|
|
|
[self setupSubviews];
|
|
[self setupConstraints];
|
|
|
|
[self marketViewClick];
|
|
}
|
|
|
|
-(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];
|
|
}
|
|
|
|
- (void)setupButtonConfig {
|
|
UIButtonConfiguration *config = [UIButtonConfiguration plainButtonConfiguration];
|
|
config.title = @"更多";
|
|
config.attributedTitle = [[NSAttributedString alloc] initWithString:@"更多" attributes:@{
|
|
NSFontAttributeName: [UIFont systemFontOfSize:14],
|
|
NSForegroundColorAttributeName: [UIColor lightGrayColor]
|
|
}];
|
|
|
|
UIImage *image = [[UIImage systemImageNamed:@"chevron.right"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
|
config.image = image;
|
|
config.imagePlacement = NSDirectionalRectEdgeTrailing; // 图片在文字右侧
|
|
config.imagePadding = 1;
|
|
|
|
config.baseForegroundColor = [UIColor lightGrayColor];
|
|
|
|
_buttonConfig = config;
|
|
}
|
|
|
|
- (void)setupSectorDataConfig {
|
|
_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%"}
|
|
];
|
|
}
|
|
|
|
- (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;
|
|
[self.view addSubview:_mlxyButton];
|
|
|
|
// 大盘指数
|
|
_marketTitleLabel = [[UILabel alloc] init];
|
|
_marketTitleLabel.text = @"大盘指数";
|
|
_marketTitleLabel.textColor = [UIColor whiteColor];
|
|
_marketTitleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
|
|
_marketTitleLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[self.view addSubview:_marketTitleLabel];
|
|
|
|
// 绿色卡片
|
|
_marketView = [[UIView alloc] init];
|
|
_marketView.backgroundColor = [UIColor greenColor];
|
|
_marketView.layer.cornerRadius = 8;
|
|
_marketView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[self.view addSubview:_marketView];
|
|
|
|
_marketLine1 = [[UILabel alloc] init];
|
|
_marketLine1.text = @"富时马来西亚KLCI";
|
|
_marketLine1.textColor = [UIColor whiteColor];
|
|
_marketLine1.font = [UIFont fontWithName:@"Helvetica-Bold" size:12];
|
|
_marketLine1.textAlignment = NSTextAlignmentCenter;
|
|
_marketLine1.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_marketView addSubview:_marketLine1];
|
|
|
|
_marketLine2 = [[UILabel alloc] init];
|
|
_marketLine2.text = @"1624.500";
|
|
_marketLine2.textColor = [UIColor whiteColor];
|
|
_marketLine2.font = [UIFont boldSystemFontOfSize:17];
|
|
_marketLine2.textAlignment = NSTextAlignmentCenter;
|
|
_marketLine2.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_marketView addSubview:_marketLine2];
|
|
|
|
_marketLine3 = [[UILabel alloc] init];
|
|
_marketLine3.text = @"12.760 0.792%";
|
|
_marketLine3.textColor = [UIColor whiteColor];
|
|
_marketLine3.font = [UIFont boldSystemFontOfSize:12];
|
|
_marketLine3.textAlignment = NSTextAlignmentCenter;
|
|
_marketLine3.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_marketView addSubview:_marketLine3];
|
|
|
|
// 板块
|
|
_sectorTitleLabel = [[UILabel alloc] init];
|
|
_sectorTitleLabel.text = @"板块";
|
|
_sectorTitleLabel.textColor = [UIColor whiteColor];
|
|
_sectorTitleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
|
|
_sectorTitleLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[self.view addSubview:_sectorTitleLabel];
|
|
|
|
_sectorBtn = [UIButton buttonWithConfiguration:self.buttonConfig primaryAction:nil];
|
|
_sectorBtn.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[self.view addSubview:_sectorBtn];
|
|
|
|
_sectorCard1 = [self createSectorCardWithData:self.sectorDataConfig[0]];
|
|
[self.view addSubview:_sectorCard1];
|
|
|
|
_sectorCard2 = [self createSectorCardWithData:self.sectorDataConfig[1]];
|
|
[self.view addSubview:_sectorCard2];
|
|
|
|
_sectorCard3 = [self createSectorCardWithData:self.sectorDataConfig[2]];
|
|
[self.view addSubview:_sectorCard3];
|
|
|
|
// 股票容器
|
|
_stockContainer = [[UIView alloc] init];
|
|
_stockContainer.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[self.view addSubview:_stockContainer];
|
|
|
|
UILabel *stockTitleLabel = [[UILabel alloc] init];
|
|
stockTitleLabel.text = @"股票";
|
|
stockTitleLabel.textColor = [UIColor whiteColor];
|
|
stockTitleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
|
|
stockTitleLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_stockContainer addSubview:stockTitleLabel];
|
|
|
|
UIButton *stockBtn = [UIButton buttonWithConfiguration:self.buttonConfig primaryAction:nil];
|
|
stockBtn.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_stockContainer addSubview:stockBtn];
|
|
|
|
// 股票列表表头
|
|
_stockHeaderView = [[UIView alloc] init];
|
|
_stockHeaderView.backgroundColor = [UIColor blackColor];
|
|
_stockHeaderView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_stockContainer addSubview:_stockHeaderView];
|
|
|
|
NSArray *headerTitles = @[@"名称", @"最新", @"涨幅"];
|
|
for (NSInteger i = 0; i < headerTitles.count; i++) {
|
|
UILabel *headerLabel = [[UILabel alloc] init];
|
|
headerLabel.text = headerTitles[i];
|
|
headerLabel.textColor = [UIColor lightGrayColor];
|
|
headerLabel.font = [UIFont systemFontOfSize:12];
|
|
headerLabel.textAlignment = (i == 0) ? NSTextAlignmentLeft : NSTextAlignmentRight;
|
|
headerLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_stockHeaderView addSubview:headerLabel];
|
|
|
|
if (i == 0) {
|
|
[headerLabel.leadingAnchor constraintEqualToAnchor:_stockHeaderView.leadingAnchor constant:15].active = YES;
|
|
} else if (i == 1) {
|
|
[headerLabel.widthAnchor constraintEqualToConstant:60].active = YES;
|
|
[headerLabel.trailingAnchor constraintEqualToAnchor:_stockHeaderView.trailingAnchor constant:-110].active = YES;
|
|
} else {
|
|
[headerLabel.widthAnchor constraintEqualToConstant:80].active = YES;
|
|
[headerLabel.trailingAnchor constraintEqualToAnchor:_stockHeaderView.trailingAnchor constant:-30].active = YES;
|
|
}
|
|
[headerLabel.centerYAnchor constraintEqualToAnchor:_stockHeaderView.centerYAnchor].active = YES;
|
|
}
|
|
|
|
_stockTableView = [[UITableView alloc] init];
|
|
_stockTableView.backgroundColor = [UIColor blackColor];
|
|
_stockTableView.separatorStyle = UITableViewCellSeparatorStyleNone;// 隐藏单元格之间的分隔线
|
|
//SingleLine 默认,1px的分割线
|
|
_stockTableView.delegate = self;
|
|
_stockTableView.dataSource = self;
|
|
[_stockTableView registerClass:[UITableViewCell class]// 单元格复用类
|
|
forCellReuseIdentifier:@"StockCell"];// 复用标识
|
|
_stockTableView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[_stockContainer addSubview:_stockTableView];
|
|
}
|
|
|
|
- (UIView *)createSectorCardWithData:(NSDictionary *)data {
|
|
UIView *card = [[UIView alloc] init];
|
|
card.backgroundColor = [UIColor darkGrayColor];
|
|
card.layer.cornerRadius = 8;
|
|
card.translatesAutoresizingMaskIntoConstraints = NO;
|
|
|
|
// 名称
|
|
UILabel *nameLabel = [[UILabel alloc] init];
|
|
nameLabel.text = data[@"name"];
|
|
nameLabel.textColor = [UIColor whiteColor];
|
|
nameLabel.font = [UIFont systemFontOfSize:14];
|
|
nameLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[card addSubview:nameLabel];
|
|
|
|
// 数值
|
|
UILabel *value1Label = [[UILabel alloc] init];
|
|
value1Label.text = data[@"value1"];
|
|
value1Label.textColor = [UIColor greenColor];
|
|
value1Label.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
|
|
value1Label.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[card addSubview:value1Label];
|
|
|
|
// 涨幅
|
|
UILabel *value2Label = [[UILabel alloc] init];
|
|
value2Label.text = data[@"value2"];
|
|
value2Label.textColor = [UIColor greenColor];
|
|
value2Label.font = [UIFont systemFontOfSize:12];
|
|
value2Label.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[card addSubview:value2Label];
|
|
|
|
UILabel *value3Label = [[UILabel alloc] init];
|
|
value3Label.text = data[@"value3"];
|
|
value3Label.textColor = [UIColor greenColor];
|
|
value3Label.font = [UIFont systemFontOfSize:12];
|
|
value3Label.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[card addSubview:value3Label];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[nameLabel.topAnchor constraintEqualToAnchor:card.topAnchor constant:7],
|
|
[nameLabel.leadingAnchor constraintEqualToAnchor:card.leadingAnchor constant:10],
|
|
|
|
[value1Label.topAnchor constraintEqualToAnchor:nameLabel.bottomAnchor constant:10],
|
|
[value1Label.leadingAnchor constraintEqualToAnchor:card.leadingAnchor constant:10],
|
|
|
|
[value2Label.topAnchor constraintEqualToAnchor:value1Label.bottomAnchor constant:7],
|
|
[value2Label.leadingAnchor constraintEqualToAnchor:card.leadingAnchor constant:10],
|
|
|
|
[value3Label.topAnchor constraintEqualToAnchor:value2Label.bottomAnchor constant:6],
|
|
[value3Label.leadingAnchor constraintEqualToAnchor:card.leadingAnchor constant:10]
|
|
]];
|
|
|
|
return card;
|
|
}
|
|
|
|
- (void)setupConstraints {
|
|
// 马来西亚按钮
|
|
NSLayoutConstraint *btnTop = [_mlxyButton.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor];
|
|
NSLayoutConstraint *btnLeft = [_mlxyButton.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor constant:15];
|
|
NSLayoutConstraint *btnWidth = [_mlxyButton.widthAnchor constraintEqualToConstant:90];
|
|
NSLayoutConstraint *btnHeight = [_mlxyButton.heightAnchor constraintEqualToConstant:30];
|
|
[NSLayoutConstraint activateConstraints:@[btnTop, btnLeft, btnWidth, btnHeight]];
|
|
|
|
// 大盘
|
|
NSLayoutConstraint *marketTitleTop = [_marketTitleLabel.topAnchor constraintEqualToAnchor:_mlxyButton.bottomAnchor constant:10];
|
|
NSLayoutConstraint *marketTitleLeft = [_marketTitleLabel.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor constant:15];
|
|
[NSLayoutConstraint activateConstraints:@[marketTitleTop, marketTitleLeft]];
|
|
|
|
NSLayoutConstraint *marketCardTop = [_marketView.topAnchor constraintEqualToAnchor:_marketTitleLabel.bottomAnchor constant:10];
|
|
NSLayoutConstraint *marketCardLeft = [_marketView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor constant:15];
|
|
NSLayoutConstraint *marketCardWidth = [_marketView.widthAnchor constraintEqualToAnchor:self.view.widthAnchor multiplier:0.3];
|
|
NSLayoutConstraint *marketCardHeight = [_marketView.heightAnchor constraintEqualToConstant:100];
|
|
[NSLayoutConstraint activateConstraints:@[marketCardTop, marketCardLeft, marketCardWidth, marketCardHeight]];
|
|
|
|
NSLayoutConstraint *line1Top = [_marketLine1.topAnchor constraintEqualToAnchor:_marketView.topAnchor constant:10];
|
|
NSLayoutConstraint *line1CenterX = [_marketLine1.centerXAnchor constraintEqualToAnchor:_marketView.centerXAnchor];
|
|
|
|
NSLayoutConstraint *line2Top = [_marketLine2.topAnchor constraintEqualToAnchor:_marketLine1.bottomAnchor constant:15];
|
|
NSLayoutConstraint *line2CenterX = [_marketLine2.centerXAnchor constraintEqualToAnchor:_marketView.centerXAnchor];
|
|
|
|
NSLayoutConstraint *line3Top = [_marketLine3.topAnchor constraintEqualToAnchor:_marketLine2.bottomAnchor constant:12];
|
|
NSLayoutConstraint *line3CenterX = [_marketLine3.centerXAnchor constraintEqualToAnchor:_marketView.centerXAnchor];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[line1Top, line1CenterX, line2Top, line2CenterX, line3Top, line3CenterX]];
|
|
|
|
// 板块
|
|
NSLayoutConstraint *sectorTitleTop = [_sectorTitleLabel.topAnchor constraintEqualToAnchor:_marketView.bottomAnchor constant:20];
|
|
NSLayoutConstraint *sectorTitleLeft = [_sectorTitleLabel.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor constant:15];
|
|
[NSLayoutConstraint activateConstraints:@[sectorTitleTop, sectorTitleLeft]];
|
|
|
|
NSLayoutConstraint *sectorBtnTop = [_sectorBtn.centerYAnchor constraintEqualToAnchor:_sectorTitleLabel.centerYAnchor];
|
|
NSLayoutConstraint *sectorBtnRight = [_sectorBtn.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor constant:-15];
|
|
[NSLayoutConstraint activateConstraints:@[sectorBtnTop, sectorBtnRight]];
|
|
|
|
NSLayoutConstraint *card1Top = [_sectorCard1.topAnchor constraintEqualToAnchor:_sectorTitleLabel.bottomAnchor constant:10];
|
|
NSLayoutConstraint *card1Left = [_sectorCard1.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor constant:8];
|
|
NSLayoutConstraint *card1Width = [_sectorCard1.widthAnchor constraintEqualToAnchor:self.view.widthAnchor multiplier:0.3];
|
|
NSLayoutConstraint *card1Height = [_sectorCard1.heightAnchor constraintEqualToConstant:100];
|
|
[NSLayoutConstraint activateConstraints:@[card1Top, card1Left, card1Width, card1Height]];
|
|
|
|
NSLayoutConstraint *card2Top = [_sectorCard2.topAnchor constraintEqualToAnchor:_sectorCard1.topAnchor];
|
|
NSLayoutConstraint *card2Left = [_sectorCard2.leadingAnchor constraintEqualToAnchor:_sectorCard1.trailingAnchor constant:8];
|
|
NSLayoutConstraint *card2Width = [_sectorCard2.widthAnchor constraintEqualToAnchor:_sectorCard1.widthAnchor];
|
|
NSLayoutConstraint *card2Height = [_sectorCard2.heightAnchor constraintEqualToAnchor:_sectorCard1.heightAnchor];
|
|
[NSLayoutConstraint activateConstraints:@[card2Top, card2Left, card2Width, card2Height]];
|
|
|
|
NSLayoutConstraint *card3Top = [_sectorCard3.topAnchor constraintEqualToAnchor:_sectorCard1.topAnchor];
|
|
NSLayoutConstraint *card3Left = [_sectorCard3.leadingAnchor constraintEqualToAnchor:_sectorCard2.trailingAnchor constant:8];
|
|
NSLayoutConstraint *card3Right = [_sectorCard3.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor constant:-16];
|
|
// *card3Width = [_sectorCard3.widthAnchor constraintEqualToAnchor:_sectorCard1.widthAnchor];都行
|
|
NSLayoutConstraint *card3Height = [_sectorCard3.heightAnchor constraintEqualToAnchor:_sectorCard1.heightAnchor];
|
|
[NSLayoutConstraint activateConstraints:@[card3Top, card3Left, card3Right, card3Height]];
|
|
|
|
// 股票容器
|
|
NSLayoutConstraint *stockTop = [_stockContainer.topAnchor constraintEqualToAnchor:_sectorCard1.bottomAnchor constant:20];
|
|
NSLayoutConstraint *stockLeft = [_stockContainer.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor];
|
|
NSLayoutConstraint *stockRight = [_stockContainer.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor];
|
|
NSLayoutConstraint *stockBottom = [_stockContainer.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor];
|
|
[NSLayoutConstraint activateConstraints:@[stockTop, stockLeft, stockRight, stockBottom]];
|
|
|
|
UILabel *stockTitleLabel = _stockContainer.subviews[0];
|
|
UIButton *stockBtn = _stockContainer.subviews[1];
|
|
|
|
NSLayoutConstraint *stockTitleTop = [stockTitleLabel.topAnchor constraintEqualToAnchor:_stockContainer.topAnchor constant:15];
|
|
NSLayoutConstraint *stockTitleLeft = [stockTitleLabel.leadingAnchor constraintEqualToAnchor:_stockContainer.leadingAnchor constant:15];
|
|
|
|
NSLayoutConstraint *stockBtnTop = [stockBtn.centerYAnchor constraintEqualToAnchor:stockTitleLabel.centerYAnchor];
|
|
NSLayoutConstraint *stockBtnRight = [stockBtn.trailingAnchor constraintEqualToAnchor:_stockContainer.trailingAnchor constant:-15];
|
|
|
|
[NSLayoutConstraint activateConstraints:@[stockTitleTop, stockTitleLeft, stockBtnTop, stockBtnRight]];
|
|
|
|
// 股票表头
|
|
NSLayoutConstraint *headerTop = [_stockHeaderView.topAnchor constraintEqualToAnchor:stockTitleLabel.bottomAnchor constant:10];
|
|
NSLayoutConstraint *headerLeft = [_stockHeaderView.leadingAnchor constraintEqualToAnchor:_stockContainer.leadingAnchor];
|
|
NSLayoutConstraint *headerRight = [_stockHeaderView.trailingAnchor constraintEqualToAnchor:_stockContainer.trailingAnchor];
|
|
NSLayoutConstraint *headerHeight = [_stockHeaderView.heightAnchor constraintEqualToConstant:30];
|
|
[NSLayoutConstraint activateConstraints:@[headerTop, headerLeft, headerRight, headerHeight]];
|
|
|
|
// 股票列表
|
|
NSLayoutConstraint *tableTop = [_stockTableView.topAnchor constraintEqualToAnchor:_stockHeaderView.bottomAnchor];
|
|
NSLayoutConstraint *tableLeft = [_stockTableView.leadingAnchor constraintEqualToAnchor:_stockContainer.leadingAnchor];
|
|
NSLayoutConstraint *tableRight = [_stockTableView.trailingAnchor constraintEqualToAnchor:_stockContainer.trailingAnchor];
|
|
NSLayoutConstraint *tableBottom = [_stockTableView.bottomAnchor constraintEqualToAnchor:_stockContainer.bottomAnchor];
|
|
[NSLayoutConstraint activateConstraints:@[tableTop, tableLeft, tableRight, tableBottom]];
|
|
}
|
|
|
|
#pragma mark - UITableView
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
return 4;
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
UITableViewCell *cell = [tableView 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 *stock = stocks[indexPath.row];
|
|
|
|
// 名称
|
|
UILabel *nameLabel = [[UILabel alloc] init];
|
|
nameLabel.text = stock[@"name"];
|
|
nameLabel.textColor = [UIColor whiteColor];
|
|
nameLabel.font = [UIFont systemFontOfSize:14];
|
|
nameLabel.numberOfLines = 1;
|
|
nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
nameLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[cell.contentView addSubview:nameLabel];
|
|
|
|
// 代码
|
|
UILabel *codeLabel = [[UILabel alloc] init];
|
|
codeLabel.text = stock[@"code"];
|
|
codeLabel.textColor = [UIColor lightGrayColor];
|
|
codeLabel.font = [UIFont systemFontOfSize:12];
|
|
codeLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[cell.contentView addSubview:codeLabel];
|
|
|
|
// 价格
|
|
UILabel *priceLabel = [[UILabel alloc] init];
|
|
priceLabel.text = stock[@"price"];
|
|
priceLabel.textColor = [UIColor greenColor];
|
|
priceLabel.font = [UIFont systemFontOfSize:14];
|
|
priceLabel.textAlignment = NSTextAlignmentRight;
|
|
priceLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[cell.contentView addSubview:priceLabel];
|
|
|
|
// 涨幅
|
|
UILabel *value2Label = [[UILabel alloc] init];
|
|
value2Label.text = stock[@"value2"];
|
|
value2Label.textColor = [UIColor greenColor];
|
|
value2Label.font = [UIFont systemFontOfSize:14];
|
|
value2Label.textAlignment = NSTextAlignmentRight;
|
|
value2Label.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[cell.contentView addSubview:value2Label];
|
|
|
|
// 约束
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[nameLabel.leadingAnchor constraintEqualToAnchor:cell.contentView.leadingAnchor constant:15],
|
|
[nameLabel.topAnchor constraintEqualToAnchor:cell.contentView.topAnchor constant:10],
|
|
[nameLabel.trailingAnchor constraintLessThanOrEqualToAnchor:priceLabel.leadingAnchor constant:-10],
|
|
|
|
[codeLabel.leadingAnchor constraintEqualToAnchor:cell.contentView.leadingAnchor constant:15],
|
|
[codeLabel.topAnchor constraintEqualToAnchor:nameLabel.bottomAnchor constant:5],
|
|
|
|
[priceLabel.widthAnchor constraintEqualToConstant:60],
|
|
[priceLabel.trailingAnchor constraintEqualToAnchor:value2Label.leadingAnchor constant:-10],
|
|
[priceLabel.centerYAnchor constraintEqualToAnchor:cell.contentView.centerYAnchor],
|
|
|
|
[value2Label.widthAnchor constraintEqualToConstant:80],
|
|
[value2Label.trailingAnchor constraintEqualToAnchor:cell.contentView.trailingAnchor constant:-15],
|
|
[value2Label.centerYAnchor constraintEqualToAnchor:cell.contentView.centerYAnchor]
|
|
]];
|
|
|
|
return cell;
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
return 60;
|
|
}
|
|
|
|
@end
|