BDFaceAdjustParamsRootController.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // BDFaceAdjustParamsRootController.m
  3. // FaceSDKSample_IOS
  4. //
  5. // Created by Zhang,Jian(MBD) on 2020/12/1.
  6. // Copyright © 2020 Baidu. All rights reserved.
  7. //
  8. #import "BDFaceAdjustParamsRootController.h"
  9. #import "BDFaceAdjustParamsRootCell.h"
  10. #import "BDFaceCalculateTool.h"
  11. #import "BDFaceAdjustParamsConstants.h"
  12. #import "UIColor+BDFaceColorUtils.h"
  13. static float const BDFaceAdjustParamsNavigationBarHeight = 44.0f;
  14. static float const BDFaceAdjustParamsNavigationBarTitleLabelOriginX = 80.0f;
  15. static float const BDFaceAdjustParamsNavigationBarBackButtonWidth = 60.0f;
  16. @interface BDFaceAdjustParamsRootController ()<UITableViewDataSource>
  17. @property(nonatomic, strong) NSMutableArray *dataSourceArray; /**<必须是@[array, array[]的格式*/
  18. @property(nonatomic, copy) NSString *reuseLabel;
  19. @property(nonatomic, copy) NSString *cellClassString;
  20. @property(nonatomic, strong) UIView *titleSeperator;
  21. @property(nonatomic, strong) UIButton *goBackButton;
  22. @end
  23. @implementation BDFaceAdjustParamsRootController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. // Do any additional setup after loading the view.
  27. [self loadTitleView];
  28. CGRect tableViewRect = CGRectMake(0, CGRectGetMaxY(self.titleView.frame), [BDFaceCalculateTool screenWidth], [BDFaceCalculateTool screenHeight] - [BDFaceCalculateTool safeTopMargin] - BDFaceAdjustParamsNavigationBarHeight);
  29. self.tableView = [[UITableView alloc] initWithFrame:tableViewRect style:[self customTableViewStyle]];
  30. [self.view addSubview:self.tableView];
  31. self.view.backgroundColor = [UIColor face_colorWithRGBHex:BDFaceAdjustParamsTableBackgroundColor];
  32. self.tableView.backgroundColor = [UIColor face_colorWithRGBHex:BDFaceAdjustParamsTableBackgroundColor];
  33. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  34. self.titleLabel.textColor = [UIColor blackColor];
  35. }
  36. - (UITableViewStyle)customTableViewStyle {
  37. return UITableViewStylePlain;
  38. }
  39. - (void)loadTitleView {
  40. CGFloat originY = [BDFaceCalculateTool safeTopMargin];
  41. if (originY == 0) {
  42. originY = 20.0f;
  43. }
  44. CGRect titleRect = CGRectMake(0, originY, [BDFaceCalculateTool screenWidth], BDFaceAdjustParamsNavigationBarHeight);
  45. self.titleView = [[UIView alloc] initWithFrame:titleRect];
  46. [self.view addSubview:self.titleView];
  47. _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(BDFaceAdjustParamsNavigationBarTitleLabelOriginX, 0, [BDFaceCalculateTool screenWidth] - BDFaceAdjustParamsNavigationBarTitleLabelOriginX * 2.0, BDFaceAdjustParamsNavigationBarHeight)];
  48. _titleLabel.textAlignment = NSTextAlignmentCenter;
  49. [self.titleView addSubview:_titleLabel];
  50. _titleLabel.font = [UIFont boldSystemFontOfSize:BDFaceAdjustConfigControllerTitleFontSize];
  51. CGFloat titleSeperatorHeight = 1.0f / [UIScreen mainScreen].scale;
  52. self.titleSeperator = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_titleLabel.frame) - titleSeperatorHeight, [BDFaceCalculateTool screenWidth], titleSeperatorHeight)];
  53. [self.titleView addSubview:self.titleSeperator];
  54. self.titleSeperator.backgroundColor = [UIColor face_colorWithRGBHex:BDFaceAdjustParamsSeperatorColor];
  55. self.goBackButton = [UIButton buttonWithType:UIButtonTypeCustom];
  56. self.goBackButton.frame = CGRectMake(0, 0, BDFaceAdjustParamsNavigationBarBackButtonWidth, CGRectGetHeight(self.titleView.frame));
  57. [self.titleView addSubview:self.goBackButton];
  58. [self.goBackButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
  59. [self.goBackButton setImage:[UIImage imageNamed:@"icon_titlebar_back"] forState:UIControlStateNormal];
  60. [self.goBackButton setImage:[UIImage imageNamed:@"icon_titlebar_back_p"] forState:UIControlStateHighlighted];
  61. self.goBackButton.imageView.contentMode = UIViewContentModeCenter;
  62. }
  63. - (void)loadTableWithCellClass:(Class)cellClass
  64. reuseLabel:(NSString *)reuseLabel
  65. dataSourceArray:(NSMutableArray *)array {
  66. [self.tableView registerClass:cellClass forCellReuseIdentifier:reuseLabel];
  67. self.reuseLabel = reuseLabel;
  68. self.cellClassString = NSStringFromClass(cellClass);
  69. self.dataSourceArray = array;
  70. self.tableView.dataSource = self;
  71. self.tableView.delegate = self;
  72. }
  73. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  74. if (!self.dataSourceArray
  75. || self.dataSourceArray.count == 0) {
  76. return 0;
  77. }
  78. if (section < self.dataSourceArray.count) {
  79. NSArray *array = self.dataSourceArray[section];
  80. if (array
  81. && [array isKindOfClass:[NSArray class]]) {
  82. return array.count;
  83. } else {
  84. return 0;
  85. }
  86. } else {
  87. return 0;
  88. }
  89. }
  90. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  91. BDFaceAdjustParamsRootCell *cell = [tableView dequeueReusableCellWithIdentifier:self.reuseLabel];
  92. if (indexPath.section < self.dataSourceArray.count) {
  93. NSArray *array = self.dataSourceArray[indexPath.section];
  94. if (indexPath.row < array.count) {
  95. cell.data = array[indexPath.row];
  96. cell.indexPath = indexPath;
  97. [cell cellFinishLoad:array.count];
  98. [self updateCellContent:cell indexPath:indexPath];
  99. }
  100. }
  101. return cell;
  102. }
  103. - (void)updateCellContent:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath {
  104. // do nothing
  105. }
  106. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  107. BDFaceAdjustParamsRootCell *cell = [tableView dequeueReusableCellWithIdentifier:self.reuseLabel];
  108. return [cell.class HeightOfFaceAdjustCell];
  109. }
  110. - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
  111. return self.dataSourceArray.count;
  112. }
  113. - (void)goBack {
  114. }
  115. @end