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

1 month ago
  1. //
  2. // MLXYViewController.m
  3. // HC
  4. //
  5. // Created by huilinLi on 2025/11/26.
  6. //
  7. #import "MLXYViewController.h"
  8. #import "ChartViewController.h"
  9. #pragma mark - cell们
  10. static NSString *const stockCell = @"StockCell";// 股票cell
  11. static NSString *const permCell = @"PermCell";// 接口cell
  12. @interface MLXYViewController () <UITableViewDataSource, UITableViewDelegate>
  13. #pragma mark - Config
  14. @property (nonatomic, strong) UIButtonConfiguration *buttonConfig;
  15. @property (nonatomic, strong) NSArray *sectorDataConfig;
  16. @property (nonatomic, strong) NSMutableArray *permissionDataList;
  17. #pragma mark - 滚动相关
  18. @property (nonatomic, strong) UIScrollView *globalScrollView;
  19. @property (nonatomic, strong) UIView *scrollContentView;
  20. @property (nonatomic, strong) UIButton *mlxyButton;
  21. #pragma mark - 大盘
  22. @property (nonatomic, strong) UILabel *marketTitleLabel;
  23. @property (nonatomic, strong) UIView *marketView;
  24. @property (nonatomic, strong) UILabel *marketLine1;
  25. @property (nonatomic, strong) UILabel *marketLine2;
  26. @property (nonatomic, strong) UILabel *marketLine3;
  27. #pragma mark - 板块
  28. @property (nonatomic, strong) UILabel *sectorTitleLabel;
  29. @property (nonatomic, strong) UIButton *sectorBtn;
  30. @property (nonatomic, strong) UIView *sectorCard1;
  31. @property (nonatomic, strong) UIView *sectorCard2;
  32. @property (nonatomic, strong) UIView *sectorCard3;
  33. #pragma mark - 股票容器
  34. @property (nonatomic, strong) UIView *stockContainer;
  35. @property (nonatomic, strong) UIView *stockHeaderView;
  36. @property (nonatomic, strong) UITableView *stockTableView;
  37. #pragma mark - 接口容器
  38. @property (nonatomic, strong) UIView *stockContainer1;
  39. @property (nonatomic, strong) UILabel *stockLabel1;
  40. @property (nonatomic, strong) UIView *permissionHeaderView;
  41. @property (nonatomic, strong) UITableView *permissionTableView;
  42. @end
  43. @implementation MLXYViewController
  44. #pragma mark - viewDidLoad
  45. - (void)viewDidLoad {
  46. [super viewDidLoad];
  47. self.view.backgroundColor = [UIColor blackColor];
  48. [self setupData];
  49. [self setupGlobalScrollView];
  50. [self setupSubviews];
  51. [self marketViewClick];
  52. [self setupConstraints];
  53. [self fetchPermissionData];
  54. }
  55. #pragma mark - 数据
  56. - (void)setupData {
  57. _permissionDataList = [NSMutableArray array];
  58. _sectorDataConfig = @[
  59. @{@"name":@"Health", @"value1":@"1099.683", @"value2":@"27.236",@"value3":@"2.270%"},
  60. @{@"name":@"Others", @"value1":@"2083.783", @"value2":@"0.000",@"value3":@"0.000%"},
  61. @{@"name":@"HLKLI", @"value1":@"987.895", @"value2":@"-1.854",@"value3":@"-0.230%"}
  62. ];
  63. UIButtonConfiguration *config = [UIButtonConfiguration plainButtonConfiguration];
  64. config.title = @"更多";
  65. config.attributedTitle = [[NSAttributedString alloc] initWithString:@"更多" attributes:@{
  66. NSFontAttributeName: [UIFont systemFontOfSize:14],
  67. NSForegroundColorAttributeName: [UIColor lightGrayColor]// 文字颜色
  68. }];
  69. config.image = [UIImage systemImageNamed:@"chevron.right"];
  70. config.imagePlacement = NSDirectionalRectEdgeTrailing;
  71. config.imagePadding = 1;
  72. config.baseForegroundColor = [UIColor lightGrayColor];// 按钮文字和模板都会继承这个颜色
  73. _buttonConfig = config;
  74. }
  75. #pragma mark - 发请求
  76. - (void)fetchPermissionData {
  77. NSString *urlString = @"https://hwjb.homilychart.com/dev/admin/permission/getPermission";
  78. NSURL *url = [NSURL URLWithString:urlString];
  79. NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
  80. request.HTTPMethod = @"POST";
  81. [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  82. NSString *token = @"eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIwMTQ0ZDE4MWQ3NDI0ZjljYjk1OTI0Y2RiZWQzZTlmYSIsInN1YiI6IntcImlkXCI6MTAwMDAxMyxcImFkbWluTmFtZVwiOlwi5p2O5oWn55Cz5ryU56S65py6XCIsXCJhY2NvdW50XCI6XCI5MDA0NzY4MVwiLFwicGFzc3dvcmRcIjpcIiQyYSQxMCRzSXVXMFNSMllEZFIyMGxxZnVRRXBlbDdHU2NTVmRqb1lDaXNrSmpTU0suNE5hbmN5NkUyLlwiLFwibWFjaGluZUlkXCI6XCIyMDAzMDQwMSxGQzM2RDYzOEZGM0FcIixcIm1hY2hpbmVJZHNcIjpudWxsLFwiYWRtaW5TdGF0dXNcIjoxLFwibWFya2V0XCI6bnVsbCxcIm1hcmtldHNcIjpcIuaAu-mDqFwiLFwicm9sZUtleVwiOm51bGwsXCJwb3N0aXRvblwiOlwi56CU5Y-RXCIsXCJyZW1hcmtcIjpcIuWRmOW3pVwiLFwiY3JlYXRlVGltZVwiOlwiMjAyNS0wOC0xMCAxNDozNDowOVwiLFwidXBkYXRlVGltZVwiOlwiMjAyNS0xMS0yMSAxNzo1NDo0MVwiLFwicm9sZUlkXCI6MixcInVzZXJuYW1lXCI6XCI5MDA0NzY4MVwifSIsImlzcyI6InNnIiwiaWF0IjoxNzY0OTE1NzQ5LCJleHAiOjE3NjUwMDIxNDl9.5O__C0lpO3CBHMVPOjiUsLD1Cp733aBZCcDmpkfcXSc";
  83. [request setValue:token forHTTPHeaderField:@"token"];
  84. NSDictionary *params = @{
  85. @"pageNum": @1,
  86. @"pageSize": @10,
  87. @"permission": @{ @"account": @"", @"market": @"", @"postiton": @"" }
  88. };
  89. // 参数转json
  90. NSError *error;
  91. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error];
  92. if (!error) {request.HTTPBody = jsonData;
  93. }else{
  94. NSLog(@"参数转json失败%@",error);
  95. return;
  96. }
  97. NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
  98. if (error) {
  99. NSLog(@"请求失败: %@", error);
  100. return;
  101. }
  102. if (data) {
  103. NSError *jsonError;
  104. NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
  105. if (!jsonError && [json[@"code"] integerValue] == 200) {
  106. NSArray *list = json[@"data"][@"list"];
  107. [self.permissionDataList removeAllObjects];
  108. [self.permissionDataList addObjectsFromArray:list];
  109. dispatch_async(dispatch_get_main_queue(), ^{
  110. [self.permissionTableView reloadData];
  111. });
  112. }
  113. }
  114. }];
  115. [task resume];
  116. }
  117. #pragma mark - 子视图们
  118. - (void)setupGlobalScrollView {
  119. _globalScrollView = [[UIScrollView alloc] init];
  120. _globalScrollView.backgroundColor = [UIColor blackColor];
  121. _globalScrollView.showsVerticalScrollIndicator = YES;
  122. _globalScrollView.translatesAutoresizingMaskIntoConstraints = NO;
  123. [self.view addSubview:_globalScrollView];
  124. _scrollContentView = [[UIView alloc] init];
  125. _scrollContentView.backgroundColor = [UIColor blackColor];
  126. _scrollContentView.translatesAutoresizingMaskIntoConstraints = NO;
  127. [_globalScrollView addSubview:_scrollContentView];
  128. }
  129. - (void)setupSubviews {
  130. _mlxyButton = [UIButton buttonWithType:UIButtonTypeSystem];
  131. [_mlxyButton setTitle:@"马来西亚" forState:UIControlStateNormal];
  132. [_mlxyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  133. [_mlxyButton setBackgroundColor:[UIColor blueColor]];
  134. _mlxyButton.layer.cornerRadius = 15;
  135. _mlxyButton.titleLabel.font = [UIFont systemFontOfSize:14];
  136. _mlxyButton.translatesAutoresizingMaskIntoConstraints = NO;
  137. [_scrollContentView addSubview:_mlxyButton];
  138. // 大盘
  139. [self setupMarketUI];
  140. // 板块
  141. [self setupSectorUI];
  142. // 股票
  143. [self setupStockListUI];
  144. // 接口
  145. [self setupPermissionUI];
  146. }
  147. - (void)setupMarketUI {
  148. _marketTitleLabel = [self createTitleLabel:@"大盘指数"];
  149. [_scrollContentView addSubview:_marketTitleLabel];
  150. _marketView = [[UIView alloc] init];
  151. _marketView.backgroundColor = [UIColor greenColor];
  152. _marketView.layer.cornerRadius = 8;
  153. _marketView.translatesAutoresizingMaskIntoConstraints = NO;
  154. [_scrollContentView addSubview:_marketView];
  155. _marketLine1 = [self createMarketLabel:@"富时马来西亚KLCI" fontSize:12 isBold:YES];
  156. _marketLine2 = [self createMarketLabel:@"1624.500" fontSize:17 isBold:YES];
  157. _marketLine3 = [self createMarketLabel:@"12.760 0.792%" fontSize:12 isBold:YES];
  158. [_marketView addSubview:_marketLine1];
  159. [_marketView addSubview:_marketLine2];
  160. [_marketView addSubview:_marketLine3];
  161. }
  162. - (void)setupSectorUI {
  163. _sectorTitleLabel = [self createTitleLabel:@"板块"];
  164. [_scrollContentView addSubview:_sectorTitleLabel];
  165. _sectorBtn = [UIButton buttonWithConfiguration:self.buttonConfig primaryAction:nil];
  166. _sectorBtn.translatesAutoresizingMaskIntoConstraints = NO;
  167. [_scrollContentView addSubview:_sectorBtn];
  168. _sectorCard1 = [self createSectorCardWithData:self.sectorDataConfig[0]];
  169. _sectorCard2 = [self createSectorCardWithData:self.sectorDataConfig[1]];
  170. _sectorCard3 = [self createSectorCardWithData:self.sectorDataConfig[2]];
  171. [_scrollContentView addSubview:_sectorCard1];
  172. [_scrollContentView addSubview:_sectorCard2];
  173. [_scrollContentView addSubview:_sectorCard3];
  174. }
  175. - (void)setupStockListUI {
  176. _stockContainer = [[UIView alloc] init];
  177. _stockContainer.translatesAutoresizingMaskIntoConstraints = NO;
  178. [_scrollContentView addSubview:_stockContainer];
  179. UILabel *title = [self createTitleLabel:@"股票"];
  180. [_stockContainer addSubview:title];
  181. UIButton *btn = [UIButton buttonWithConfiguration:self.buttonConfig primaryAction:nil];
  182. btn.translatesAutoresizingMaskIntoConstraints = NO;
  183. [_stockContainer addSubview:btn];
  184. _stockHeaderView = [[UIView alloc] init];
  185. _stockHeaderView.backgroundColor = [UIColor blackColor];
  186. _stockHeaderView.translatesAutoresizingMaskIntoConstraints = NO;
  187. [_stockContainer addSubview:_stockHeaderView];
  188. [self setupHeaderLabelsForView:_stockHeaderView titles:@[@"名称", @"最新", @"涨幅"] isWhite:NO];
  189. _stockTableView = [[UITableView alloc] init];
  190. _stockTableView.backgroundColor = [UIColor blackColor];
  191. _stockTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  192. _stockTableView.delegate = self;
  193. _stockTableView.dataSource = self;
  194. _stockTableView.scrollEnabled = NO;
  195. [_stockTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:stockCell];
  196. _stockTableView.translatesAutoresizingMaskIntoConstraints = NO;
  197. [_stockContainer addSubview:_stockTableView];
  198. }
  199. - (void)setupPermissionUI {
  200. _stockContainer1 = [[UIView alloc] init];
  201. _stockContainer1.backgroundColor = [UIColor whiteColor];
  202. _stockContainer1.layer.cornerRadius = 8;
  203. _stockContainer1.translatesAutoresizingMaskIntoConstraints = NO;
  204. [_scrollContentView addSubview:_stockContainer1];
  205. _stockLabel1 = [[UILabel alloc] init];
  206. _stockLabel1.text = @"真数据!";
  207. _stockLabel1.textColor = [UIColor blackColor];
  208. _stockLabel1.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
  209. _stockLabel1.translatesAutoresizingMaskIntoConstraints = NO;
  210. [_stockContainer1 addSubview:_stockLabel1];
  211. _permissionHeaderView = [[UIView alloc] init];
  212. _permissionHeaderView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
  213. _permissionHeaderView.translatesAutoresizingMaskIntoConstraints = NO;
  214. [_stockContainer1 addSubview:_permissionHeaderView];
  215. [self setupHeaderLabelsForView:_permissionHeaderView titles:@[@"Name", @"Account", @"Market", @"Position"] isWhite:YES];
  216. _permissionTableView = [[UITableView alloc] init];
  217. _permissionTableView.backgroundColor = [UIColor whiteColor];
  218. _permissionTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  219. _permissionTableView.delegate = self;
  220. _permissionTableView.dataSource = self;
  221. _permissionTableView.scrollEnabled = NO;
  222. [_permissionTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:permCell];
  223. _permissionTableView.translatesAutoresizingMaskIntoConstraints = NO;
  224. [_stockContainer1 addSubview:_permissionTableView];
  225. }
  226. #pragma mark - 小工具
  227. - (UILabel *)createTitleLabel:(NSString *)text {
  228. UILabel *label = [[UILabel alloc] init];
  229. label.text = text;
  230. label.textColor = [UIColor whiteColor];
  231. label.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  232. label.translatesAutoresizingMaskIntoConstraints = NO;
  233. return label;
  234. }
  235. - (UILabel *)createMarketLabel:(NSString *)text fontSize:(CGFloat)size isBold:(BOOL)isBold {
  236. UILabel *label = [[UILabel alloc] init];
  237. label.text = text;
  238. label.textColor = [UIColor whiteColor];
  239. label.font = isBold ? [UIFont boldSystemFontOfSize:size] : [UIFont systemFontOfSize:size];
  240. label.textAlignment = NSTextAlignmentCenter;
  241. label.translatesAutoresizingMaskIntoConstraints = NO;
  242. return label;
  243. }
  244. - (void)setupHeaderLabelsForView:(UIView *)view titles:(NSArray *)titles isWhite:(BOOL)isWhite {
  245. CGFloat multiplier = 1.0 / titles.count;
  246. for (NSInteger i = 0; i < titles.count; i++) {
  247. UILabel *label = [[UILabel alloc] init];
  248. label.text = titles[i];
  249. label.textColor = isWhite ? [UIColor darkGrayColor] : [UIColor lightGrayColor];
  250. label.font = isWhite ? [UIFont boldSystemFontOfSize:12] : [UIFont systemFontOfSize:12];
  251. label.translatesAutoresizingMaskIntoConstraints = NO;
  252. [view addSubview:label];
  253. if (isWhite) {
  254. // 等分
  255. label.textAlignment = NSTextAlignmentCenter;
  256. [NSLayoutConstraint activateConstraints:@[
  257. [label.topAnchor constraintEqualToAnchor:view.topAnchor],
  258. [label.bottomAnchor constraintEqualToAnchor:view.bottomAnchor],
  259. [label.widthAnchor constraintEqualToAnchor:view.widthAnchor multiplier:multiplier],
  260. (i == 0) ? [label.leadingAnchor constraintEqualToAnchor:view.leadingAnchor] : [label.leadingAnchor constraintEqualToAnchor:view.subviews[i-1].trailingAnchor]
  261. ]];
  262. } else {
  263. // 股票表头
  264. label.textAlignment = (i == 0) ? NSTextAlignmentLeft : NSTextAlignmentRight;
  265. [label.centerYAnchor constraintEqualToAnchor:view.centerYAnchor].active = YES;
  266. if (i == 0) {
  267. [label.leadingAnchor constraintEqualToAnchor:view.leadingAnchor constant:15].active = YES;
  268. } else if (i == 1) {
  269. [label.widthAnchor constraintEqualToConstant:60].active = YES;
  270. [label.trailingAnchor constraintEqualToAnchor:view.trailingAnchor constant:-110].active = YES;
  271. } else {
  272. [label.widthAnchor constraintEqualToConstant:80].active = YES;
  273. [label.trailingAnchor constraintEqualToAnchor:view.trailingAnchor constant:-30].active = YES;
  274. }
  275. }
  276. }
  277. }
  278. - (UIView *)createSectorCardWithData:(NSDictionary *)data {
  279. UIView *card = [[UIView alloc] init];
  280. card.backgroundColor = [UIColor darkGrayColor];
  281. card.layer.cornerRadius = 8;
  282. card.translatesAutoresizingMaskIntoConstraints = NO;
  283. UILabel *nameLabel = [self createCardLabel:data[@"name"] color:[UIColor whiteColor] size:14 bold:NO];
  284. UILabel *val1Label = [self createCardLabel:data[@"value1"] color:[UIColor greenColor] size:16 bold:YES];
  285. UILabel *val2Label = [self createCardLabel:data[@"value2"] color:[UIColor greenColor] size:12 bold:NO];
  286. UILabel *val3Label = [self createCardLabel:data[@"value3"] color:[UIColor greenColor] size:12 bold:NO];
  287. [card addSubview:nameLabel];
  288. [card addSubview:val1Label];
  289. [card addSubview:val2Label];
  290. [card addSubview:val3Label];
  291. [NSLayoutConstraint activateConstraints:@[
  292. [nameLabel.topAnchor constraintEqualToAnchor:card.topAnchor constant:7],
  293. [nameLabel.leadingAnchor constraintEqualToAnchor:card.leadingAnchor constant:10],
  294. [val1Label.topAnchor constraintEqualToAnchor:nameLabel.bottomAnchor constant:10],
  295. [val1Label.leadingAnchor constraintEqualToAnchor:card.leadingAnchor constant:10],
  296. [val2Label.topAnchor constraintEqualToAnchor:val1Label.bottomAnchor constant:7],
  297. [val2Label.leadingAnchor constraintEqualToAnchor:card.leadingAnchor constant:10],
  298. [val3Label.topAnchor constraintEqualToAnchor:val2Label.bottomAnchor constant:6],
  299. [val3Label.leadingAnchor constraintEqualToAnchor:card.leadingAnchor constant:10]
  300. ]];
  301. return card;
  302. }
  303. - (UILabel *)createCardLabel:(NSString *)text color:(UIColor *)color size:(CGFloat)size bold:(BOOL)bold {
  304. UILabel *label = [[UILabel alloc] init];
  305. label.text = text;
  306. label.textColor = color;
  307. label.font = bold ? [UIFont boldSystemFontOfSize:size] : [UIFont systemFontOfSize:size];
  308. label.translatesAutoresizingMaskIntoConstraints = NO;
  309. return label;
  310. }
  311. #pragma mark - 约束们
  312. - (void)setupConstraints {
  313. [NSLayoutConstraint activateConstraints:@[
  314. [_globalScrollView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
  315. [_globalScrollView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
  316. [_globalScrollView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor],
  317. [_globalScrollView.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor],
  318. [_scrollContentView.leadingAnchor constraintEqualToAnchor:_globalScrollView.leadingAnchor],
  319. [_scrollContentView.trailingAnchor constraintEqualToAnchor:_globalScrollView.trailingAnchor],
  320. [_scrollContentView.topAnchor constraintEqualToAnchor:_globalScrollView.topAnchor],
  321. [_scrollContentView.bottomAnchor constraintEqualToAnchor:_globalScrollView.bottomAnchor],
  322. [_scrollContentView.widthAnchor constraintEqualToAnchor:self.view.widthAnchor]
  323. ]];
  324. [NSLayoutConstraint activateConstraints:@[
  325. [_mlxyButton.topAnchor constraintEqualToAnchor:_scrollContentView.topAnchor constant:15],
  326. [_mlxyButton.leadingAnchor constraintEqualToAnchor:_scrollContentView.leadingAnchor constant:15],
  327. [_mlxyButton.widthAnchor constraintEqualToConstant:90],
  328. [_mlxyButton.heightAnchor constraintEqualToConstant:30]
  329. ]];
  330. [NSLayoutConstraint activateConstraints:@[
  331. [_marketTitleLabel.topAnchor constraintEqualToAnchor:_mlxyButton.bottomAnchor constant:10],
  332. [_marketTitleLabel.leadingAnchor constraintEqualToAnchor:_scrollContentView.leadingAnchor constant:15],
  333. [_marketView.topAnchor constraintEqualToAnchor:_marketTitleLabel.bottomAnchor constant:10],
  334. [_marketView.leadingAnchor constraintEqualToAnchor:_scrollContentView.leadingAnchor constant:15],
  335. [_marketView.widthAnchor constraintEqualToAnchor:_scrollContentView.widthAnchor multiplier:0.3],
  336. [_marketView.heightAnchor constraintEqualToConstant:100],
  337. [_marketLine1.topAnchor constraintEqualToAnchor:_marketView.topAnchor constant:10],
  338. [_marketLine1.centerXAnchor constraintEqualToAnchor:_marketView.centerXAnchor],
  339. [_marketLine2.topAnchor constraintEqualToAnchor:_marketLine1.bottomAnchor constant:15],
  340. [_marketLine2.centerXAnchor constraintEqualToAnchor:_marketView.centerXAnchor],
  341. [_marketLine3.topAnchor constraintEqualToAnchor:_marketLine2.bottomAnchor constant:12],
  342. [_marketLine3.centerXAnchor constraintEqualToAnchor:_marketView.centerXAnchor]
  343. ]];
  344. [NSLayoutConstraint activateConstraints:@[
  345. [_sectorTitleLabel.topAnchor constraintEqualToAnchor:_marketView.bottomAnchor constant:20],
  346. [_sectorTitleLabel.leadingAnchor constraintEqualToAnchor:_scrollContentView.leadingAnchor constant:15],
  347. [_sectorBtn.centerYAnchor constraintEqualToAnchor:_sectorTitleLabel.centerYAnchor],
  348. [_sectorBtn.trailingAnchor constraintEqualToAnchor:_scrollContentView.trailingAnchor constant:-15],
  349. [_sectorCard1.topAnchor constraintEqualToAnchor:_sectorTitleLabel.bottomAnchor constant:10],
  350. [_sectorCard1.leadingAnchor constraintEqualToAnchor:_scrollContentView.leadingAnchor constant:8],
  351. [_sectorCard1.widthAnchor constraintEqualToAnchor:_scrollContentView.widthAnchor multiplier:0.3],
  352. [_sectorCard1.heightAnchor constraintEqualToConstant:100],
  353. [_sectorCard2.topAnchor constraintEqualToAnchor:_sectorCard1.topAnchor],
  354. [_sectorCard2.leadingAnchor constraintEqualToAnchor:_sectorCard1.trailingAnchor constant:8],
  355. [_sectorCard2.widthAnchor constraintEqualToAnchor:_sectorCard1.widthAnchor],
  356. [_sectorCard2.heightAnchor constraintEqualToAnchor:_sectorCard1.heightAnchor],
  357. [_sectorCard3.topAnchor constraintEqualToAnchor:_sectorCard1.topAnchor],
  358. [_sectorCard3.leadingAnchor constraintEqualToAnchor:_sectorCard2.trailingAnchor constant:8],
  359. [_sectorCard3.trailingAnchor constraintEqualToAnchor:_scrollContentView.trailingAnchor constant:-16],
  360. [_sectorCard3.heightAnchor constraintEqualToAnchor:_sectorCard1.heightAnchor]
  361. ]];
  362. UILabel *stockTitle = _stockContainer.subviews[0];
  363. UIButton *stockBtn = _stockContainer.subviews[1];
  364. [NSLayoutConstraint activateConstraints:@[
  365. [_stockContainer.topAnchor constraintEqualToAnchor:_sectorCard1.bottomAnchor constant:20],
  366. [_stockContainer.leadingAnchor constraintEqualToAnchor:_scrollContentView.leadingAnchor],
  367. [_stockContainer.trailingAnchor constraintEqualToAnchor:_scrollContentView.trailingAnchor],
  368. [_stockContainer.bottomAnchor constraintEqualToAnchor:_stockTableView.bottomAnchor constant:10],
  369. [stockTitle.topAnchor constraintEqualToAnchor:_stockContainer.topAnchor constant:15],
  370. [stockTitle.leadingAnchor constraintEqualToAnchor:_stockContainer.leadingAnchor constant:15],
  371. [stockBtn.centerYAnchor constraintEqualToAnchor:stockTitle.centerYAnchor],
  372. [stockBtn.trailingAnchor constraintEqualToAnchor:_stockContainer.trailingAnchor constant:-15],
  373. [_stockHeaderView.topAnchor constraintEqualToAnchor:stockTitle.bottomAnchor constant:10],
  374. [_stockHeaderView.leadingAnchor constraintEqualToAnchor:_stockContainer.leadingAnchor],
  375. [_stockHeaderView.trailingAnchor constraintEqualToAnchor:_stockContainer.trailingAnchor],
  376. [_stockHeaderView.heightAnchor constraintEqualToConstant:30],
  377. [_stockTableView.topAnchor constraintEqualToAnchor:_stockHeaderView.bottomAnchor],
  378. [_stockTableView.leadingAnchor constraintEqualToAnchor:_stockContainer.leadingAnchor],
  379. [_stockTableView.trailingAnchor constraintEqualToAnchor:_stockContainer.trailingAnchor],
  380. [_stockTableView.heightAnchor constraintEqualToConstant:240]
  381. ]];
  382. [NSLayoutConstraint activateConstraints:@[
  383. [_stockContainer1.topAnchor constraintEqualToAnchor:_stockContainer.bottomAnchor constant:20],
  384. [_stockContainer1.leadingAnchor constraintEqualToAnchor:_scrollContentView.leadingAnchor constant:15],
  385. [_stockContainer1.trailingAnchor constraintEqualToAnchor:_scrollContentView.trailingAnchor constant:-15],
  386. [_stockContainer1.heightAnchor constraintEqualToConstant:290], // Height approximation
  387. [_stockContainer1.bottomAnchor constraintEqualToAnchor:_scrollContentView.bottomAnchor constant:-20],
  388. [_stockLabel1.topAnchor constraintEqualToAnchor:_stockContainer1.topAnchor constant:10],
  389. [_stockLabel1.leadingAnchor constraintEqualToAnchor:_stockContainer1.leadingAnchor constant:15],
  390. [_permissionHeaderView.topAnchor constraintEqualToAnchor:_stockLabel1.bottomAnchor constant:10],
  391. [_permissionHeaderView.leadingAnchor constraintEqualToAnchor:_stockContainer1.leadingAnchor],
  392. [_permissionHeaderView.trailingAnchor constraintEqualToAnchor:_stockContainer1.trailingAnchor],
  393. [_permissionHeaderView.heightAnchor constraintEqualToConstant:30],
  394. [_permissionTableView.topAnchor constraintEqualToAnchor:_permissionHeaderView.bottomAnchor],
  395. [_permissionTableView.leadingAnchor constraintEqualToAnchor:_stockContainer1.leadingAnchor],
  396. [_permissionTableView.trailingAnchor constraintEqualToAnchor:_stockContainer1.trailingAnchor],
  397. [_permissionTableView.bottomAnchor constraintEqualToAnchor:_stockContainer1.bottomAnchor constant:-5]
  398. ]];
  399. }
  400. #pragma mark - 跳转k线
  401. -(void)marketViewClick{
  402. _marketView.userInteractionEnabled = YES;
  403. UITapGestureRecognizer *click = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(marketViewPush)];
  404. [_marketView addGestureRecognizer:click];
  405. }
  406. -(void)marketViewPush{
  407. ChartViewController *chartViewController = [[ChartViewController alloc] init];
  408. [self.navigationController pushViewController:chartViewController animated:YES];
  409. }
  410. #pragma mark - 哦哦哦哦哦
  411. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  412. if (tableView == _stockTableView) return 4;// 股票表4
  413. if (tableView == _permissionTableView) return MIN(self.permissionDataList.count, 5);// 接口最多5
  414. return 0;
  415. }
  416. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  417. return (tableView == _stockTableView) ? 60 : 44;// 行高
  418. }
  419. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  420. if (tableView == _stockTableView) {
  421. return [self stockCellForIndexPath:indexPath];
  422. } else {
  423. return [self permissionCellForIndexPath:indexPath];
  424. }
  425. }
  426. // 股票Cell
  427. - (UITableViewCell *)stockCellForIndexPath:(NSIndexPath *)indexPath {
  428. UITableViewCell *cell = [_stockTableView dequeueReusableCellWithIdentifier:stockCell forIndexPath:indexPath];
  429. cell.backgroundColor = [UIColor blackColor];
  430. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  431. [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  432. NSArray *stocks = @[
  433. @{@"name":@"PEGASUS HEIGHTS BERHAD", @"code":@"4464", @"price":@"0.010", @"value2":@"100.000%"},
  434. @{@"name":@"SMTRACK BERHAD", @"code":@"0169", @"price":@"0.010", @"value2":@"100.000%"},
  435. @{@"name":@"TXCD BERHAD - ICPS 2020/2030", @"code":@"7145PA", @"price":@"0.020", @"value2":@"33.333%"},
  436. @{@"name":@"DNONCE TECHNOLOGY BHD", @"code":@"7114", @"price":@"0.040", @"value2":@"33.333%"}
  437. ];
  438. NSDictionary *data = stocks[indexPath.row];
  439. UILabel *name = [self createCardLabel:data[@"name"] color:[UIColor whiteColor] size:14 bold:NO];
  440. name.lineBreakMode = NSLineBreakByTruncatingTail;
  441. UILabel *code = [self createCardLabel:data[@"code"] color:[UIColor lightGrayColor] size:12 bold:NO];
  442. UILabel *price = [self createCardLabel:data[@"price"] color:[UIColor greenColor] size:14 bold:NO];
  443. price.textAlignment = NSTextAlignmentRight;
  444. UILabel *val2 = [self createCardLabel:data[@"value2"] color:[UIColor greenColor] size:14 bold:NO];
  445. val2.textAlignment = NSTextAlignmentRight;
  446. [cell.contentView addSubview:name];
  447. [cell.contentView addSubview:code];
  448. [cell.contentView addSubview:price];
  449. [cell.contentView addSubview:val2];
  450. [NSLayoutConstraint activateConstraints:@[
  451. [name.leadingAnchor constraintEqualToAnchor:cell.contentView.leadingAnchor constant:15],
  452. [name.topAnchor constraintEqualToAnchor:cell.contentView.topAnchor constant:10],
  453. [name.trailingAnchor constraintLessThanOrEqualToAnchor:price.leadingAnchor constant:-10],
  454. [code.leadingAnchor constraintEqualToAnchor:cell.contentView.leadingAnchor constant:15],
  455. [code.topAnchor constraintEqualToAnchor:name.bottomAnchor constant:5],
  456. [price.widthAnchor constraintEqualToConstant:60],
  457. [price.trailingAnchor constraintEqualToAnchor:val2.leadingAnchor constant:-10],
  458. [price.centerYAnchor constraintEqualToAnchor:cell.contentView.centerYAnchor],
  459. [val2.widthAnchor constraintEqualToConstant:80],
  460. [val2.trailingAnchor constraintEqualToAnchor:cell.contentView.trailingAnchor constant:-15],
  461. [val2.centerYAnchor constraintEqualToAnchor:cell.contentView.centerYAnchor]
  462. ]];
  463. return cell;
  464. }
  465. // 接口Cell
  466. - (UITableViewCell *)permissionCellForIndexPath:(NSIndexPath *)indexPath {
  467. UITableViewCell *cell = [_permissionTableView dequeueReusableCellWithIdentifier:permCell forIndexPath:indexPath];
  468. cell.backgroundColor = [UIColor whiteColor];
  469. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  470. [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  471. NSDictionary *item = self.permissionDataList[indexPath.row];
  472. NSArray *values = @[item[@"name"] ?: @"-", item[@"account"] ?: @"-", item[@"market"] ?: @"-", item[@"postiton"] ?: @"-"];
  473. for (NSInteger i = 0; i < values.count; i++) {
  474. UILabel *label = [self createCardLabel:[NSString stringWithFormat:@"%@", values[i]] color:[UIColor blackColor] size:11 bold:NO];
  475. label.textAlignment = NSTextAlignmentCenter;
  476. label.lineBreakMode = NSLineBreakByTruncatingTail;
  477. [cell.contentView addSubview:label];
  478. [NSLayoutConstraint activateConstraints:@[
  479. [label.topAnchor constraintEqualToAnchor:cell.contentView.topAnchor],
  480. [label.bottomAnchor constraintEqualToAnchor:cell.contentView.bottomAnchor],
  481. [label.widthAnchor constraintEqualToAnchor:cell.contentView.widthAnchor multiplier:0.25],
  482. (i == 0) ? [label.leadingAnchor constraintEqualToAnchor:cell.contentView.leadingAnchor] : [label.leadingAnchor constraintEqualToAnchor:cell.contentView.subviews[i-1].trailingAnchor]
  483. ]];
  484. }
  485. return cell;
  486. }
  487. @end