FirstViewController.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // FirstViewController.m
  3. // PersonalCenter
  4. //
  5. // Created by Arch on 2017/6/16.
  6. // Copyright © 2017年 mint_bin. All rights reserved.
  7. //
  8. #import "FirstViewController.h"
  9. #import "HomeSchoolContentCell.h"
  10. @interface FirstViewController ()<UITableViewDelegate,UITableViewDataSource>
  11. @property (nonatomic, strong) UILabel * titleL;
  12. @property (nonatomic, copy) NSString * content;
  13. @property(nonatomic, strong) UITableView *tableView;
  14. @end
  15. @implementation FirstViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. self.view.backgroundColor = UIColorHex(0xF8F9FB);
  19. [self creatTableView];
  20. }
  21. - (void)creatTableView {
  22. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, SCREEN_HEIGHT - NAVH - 150) style:UITableViewStyleGrouped];
  23. _tableView.delegate = self;
  24. _tableView.dataSource = self;
  25. _tableView.showsVerticalScrollIndicator = NO;
  26. _tableView.showsHorizontalScrollIndicator = NO;
  27. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  28. _tableView.backgroundColor = [UIColor whiteColor];
  29. _tableView.rowHeight = 50;
  30. [self.view addSubview:_tableView];
  31. }
  32. - (void)setDataText:(NSString *)text
  33. {
  34. self.content = text;
  35. [self.tableView reloadData];
  36. }
  37. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  38. {
  39. return 45.f;
  40. }
  41. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  42. {
  43. return 0.01f;
  44. }
  45. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  46. {
  47. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 45)];
  48. [view addSubview:self.titleL];
  49. [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.left.mas_offset(15);
  51. make.centerY.right.mas_equalTo(view);
  52. }];
  53. return view;
  54. }
  55. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  56. {
  57. return [UIView new];
  58. }
  59. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  60. {
  61. return 1;
  62. }
  63. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  64. {
  65. return 1;
  66. }
  67. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  68. {
  69. return UITableViewAutomaticDimension;
  70. }
  71. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  72. {
  73. HomeSchoolContentCell * cell = [HomeSchoolContentCell configCell:tableView indexPath:indexPath];
  74. [cell setDataText:self.content];
  75. return cell;
  76. }
  77. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  78. {
  79. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  80. }
  81. - (UILabel *)titleL
  82. {
  83. if (!_titleL) {
  84. _titleL = [UILabel new];
  85. _titleL.font = [UIFont systemFontOfSize:16];
  86. _titleL.textColor = UIColorHex(0x222222);
  87. _titleL.text = @"学校简介";
  88. }
  89. return _titleL;
  90. }
  91. @end