BDFaceSelectConfigCell.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // BDFaceSelectConfigCell.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 "BDFaceSelectConfigCell.h"
  9. #import "BDFaceSelectItem.h"
  10. #import "UIColor+BDFaceColorUtils.h"
  11. float const BDFaceSelectConfigCellHeight = 48.0f;
  12. float const BDFaceSelectRadioMarginLeft = 5.0f;
  13. float const BDFaceSelectRadioWidth = 40;
  14. float const BDFaceSelectRadioHeight = BDFaceSelectRadioWidth;
  15. float const BDFaceSelectRadioMarginRight = 0.0f;
  16. float const BDFaceSelectTipLabelWidth = 150.0f;
  17. float const BDFaceSelectTipLabelHeight = 30.0f;
  18. float const BDFaceSelectContentRightMargin = 10.0f;
  19. float const BDFaceSelectSettingButtonWidth = 75.0f;
  20. float const BDFaceSelectSettingButtonHeight = 45.0f;
  21. float const BDFaceSelectSettingImageWidth = 28.0f;
  22. float const BDFaceSelectSettingImageHeight = 45.0f;
  23. static NSString *const BDFaceSelectConfigTip = @"参数配置";
  24. static NSString *const BDFaceSelectRightArrowImage = @"right_arrow";
  25. @interface BDFaceSelectConfigCell()
  26. @property(nonatomic, strong) UILabel *tipLabel;
  27. @property(nonatomic, strong) UIButton *settingButton;
  28. @property(nonatomic, strong) UIButton *arrowButton;
  29. @end
  30. @implementation BDFaceSelectConfigCell
  31. - (void)awakeFromNib {
  32. [super awakeFromNib];
  33. // Initialization code
  34. }
  35. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  36. [super setSelected:selected animated:animated];
  37. // Configure the view for the selected state
  38. }
  39. + (CGFloat)HeightOfFaceAdjustCell {
  40. return BDFaceSelectConfigCellHeight;
  41. }
  42. - (void)cellFinishLoad:(NSInteger)rowsInSection {
  43. [super cellFinishLoad:rowsInSection];
  44. BDFaceSelectItem *item = (BDFaceSelectItem *)self.data;
  45. if (!self.radio) {
  46. BDFaceSelectRadio *radio = [BDFaceSelectRadio buttonWithType:UIButtonTypeCustom selected:NO];
  47. self.backgroundColor = [UIColor whiteColor];
  48. [self addSubview:radio];
  49. self.radio = radio;
  50. __weak typeof(self) weakSelf = self;
  51. self.radio.radioTaped = ^(NSInteger theIndex, BOOL selected) {
  52. weakSelf.arrowButton.hidden = !selected;
  53. weakSelf.settingButton.hidden = !selected;
  54. };
  55. }
  56. if (!self.tipLabel) {
  57. self.tipLabel = [[UILabel alloc]init];
  58. self.tipLabel.textColor = [UIColor blackColor];
  59. [self addSubview:self.tipLabel];
  60. self.tipLabel.font = [UIFont systemFontOfSize:BDFaceAdjustConfigContentTitleFontSize];
  61. }
  62. self.tipLabel.text = item.itemTitle;
  63. if (!self.settingButton) {
  64. self.settingButton = [UIButton buttonWithType:UIButtonTypeCustom];
  65. [self addSubview:self.settingButton];
  66. [self.settingButton setTitle:BDFaceSelectConfigTip forState:UIControlStateNormal];
  67. self.settingButton.titleLabel.textAlignment = NSTextAlignmentRight;
  68. [self.settingButton setTitleColor:[UIColor face_colorWithRGBHex:BDFaceAdjustConfigTipTextColor] forState:UIControlStateNormal];
  69. [self.settingButton addTarget:self action:@selector(userDidChooseToAdjustParams) forControlEvents:UIControlEventTouchUpInside];
  70. self.settingButton.titleLabel.font = [UIFont systemFontOfSize:BDFaceAdjustConfigContentTitleFontSize];
  71. }
  72. if (!self.arrowButton) {
  73. self.arrowButton = [[UIButton alloc] init];
  74. [self addSubview:self.arrowButton];
  75. [self.arrowButton setImage:[UIImage imageNamed:BDFaceSelectRightArrowImage] forState:UIControlStateNormal];
  76. [self.arrowButton addTarget:self action:@selector(userDidChooseToAdjustParams) forControlEvents:UIControlEventTouchUpInside];
  77. }
  78. self.selectionStyle = UITableViewCellSelectionStyleNone;
  79. }
  80. - (void)layoutSubviews {
  81. [super layoutSubviews];
  82. self.radio.frame = CGRectMake(BDFaceSelectRadioMarginLeft, (BDFaceSelectConfigCellHeight - BDFaceSelectRadioHeight) / 2.0f, BDFaceSelectRadioWidth, BDFaceSelectRadioHeight);
  83. self.tipLabel.frame =CGRectMake(CGRectGetMaxX(self.radio.frame) + BDFaceSelectRadioMarginRight, (BDFaceSelectConfigCellHeight - BDFaceSelectTipLabelHeight) / 2.0, BDFaceSelectTipLabelWidth, BDFaceSelectTipLabelHeight);
  84. CGFloat settingButtonOriginX = CGRectGetWidth(self.frame) - BDFaceSelectSettingButtonWidth - BDFaceSelectSettingImageWidth - BDFaceSelectContentRightMargin;
  85. self.settingButton.frame = CGRectMake(settingButtonOriginX, (BDFaceSelectConfigCellHeight - BDFaceSelectSettingButtonHeight) / 2.0f, BDFaceSelectSettingButtonWidth, BDFaceSelectSettingButtonHeight);
  86. self.arrowButton.frame = CGRectMake(CGRectGetMaxX(self.settingButton.frame), (BDFaceSelectConfigCellHeight - BDFaceSelectSettingImageHeight) / 2.0f, BDFaceSelectSettingImageWidth, BDFaceSelectSettingImageHeight);
  87. self.settingButton.titleLabel.frame = self.settingButton.bounds;
  88. [self setConerRadius:BDFaceAdjustConfigTableCornerRadius borderWidth:(1.0f / UIScreen.mainScreen.scale) borderColor:nil];
  89. }
  90. - (void)userDidChooseToAdjustParams {
  91. BDFaceSelectItem *item = (BDFaceSelectItem *)self.data;
  92. if (self.adjustConfigAction) {
  93. self.adjustConfigAction(item.itemType);
  94. }
  95. }
  96. - (void)showSettingButton:(BOOL)show {
  97. self.settingButton.hidden = !show;
  98. self.arrowButton.hidden = !show;
  99. }
  100. @end