XYSetupTableViewCell.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // XYSetupTableViewCell.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2019/12/30.
  6. // Copyright © 2019 翟玉磊. All rights reserved.
  7. //
  8. #import "XYSetupTableViewCell.h"
  9. #import "XYSetupCellModel.h"
  10. @interface XYSetupTableViewCell ()
  11. @property (nonatomic, readwrite, strong) UILabel *titleLabel;
  12. @property (nonatomic, readwrite, strong) UILabel *disLabel;
  13. @property (nonatomic, readwrite, strong) UIImageView *moreImageView;
  14. @property (nonatomic, readwrite, strong) UIView *lineView;
  15. @end
  16. @implementation XYSetupTableViewCell
  17. #pragma mark - Public Method
  18. + (instancetype)cellWithTableView:(UITableView *)tableView {
  19. static NSString * const cellId = @"XYSetupTableViewCell";
  20. XYSetupTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
  21. if (!cell) {
  22. cell = [[XYSetupTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
  23. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  24. }
  25. return cell;
  26. }
  27. - (void)configureModel:(XYSetupCellModel *)model {
  28. self.titleLabel.text = model.title;
  29. self.disLabel.text = model.disStr;
  30. self.moreImageView.hidden = !model.isShowMore;
  31. self.switchView.hidden = !model.isShowSwitch;
  32. self.lineView.hidden = !model.isShowBottomLine;
  33. self.switchView.on = model.switchStatus;
  34. }
  35. #pragma mark - 初始化
  36. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  37. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  38. // 初始化
  39. [self _setup];
  40. // 创建自控制器
  41. [self _setupSubViews];
  42. // 布局子控件
  43. [self _makeSubViewsConstraints];
  44. }
  45. return self;
  46. }
  47. #pragma mark - 事件处理Or辅助方法
  48. #pragma mark - Private Method
  49. - (void)_setup{
  50. self.backgroundColor = UIColor.whiteColor;
  51. }
  52. #pragma mark - 创建子控件
  53. - (void)_setupSubViews{
  54. [self.contentView addSubview:self.titleLabel];
  55. [self.contentView addSubview:self.disLabel];
  56. [self.contentView addSubview:self.moreImageView];
  57. [self.contentView addSubview:self.switchView];
  58. [self.contentView addSubview:self.lineView];
  59. }
  60. #pragma mark - 布局子控件
  61. - (void)_makeSubViewsConstraints{
  62. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.left.equalTo(self.contentView).offset(SPACING_EDGE);
  64. make.centerY.equalTo(self.contentView);
  65. }];
  66. [self.disLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.right.equalTo(self.contentView.mas_right).offset(-40);
  68. make.centerY.equalTo(self.contentView);
  69. }];
  70. [self.moreImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.right.equalTo(self.contentView).offset(-SPACING_EDGE);
  72. make.centerY.equalTo(self.contentView);
  73. make.width.equalTo(@6.0f);
  74. make.height.equalTo(@10.0f);
  75. }];
  76. [self.switchView mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.right.equalTo(self.contentView).offset(-SPACING_EDGE);
  78. make.centerY.equalTo(self.contentView);
  79. make.width.equalTo(@48.0f);
  80. make.height.equalTo(@26.0f);
  81. }];
  82. [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.left.bottom.right.equalTo(self.contentView);
  84. make.height.equalTo(@0.3f);
  85. }];
  86. }
  87. - (void)awakeFromNib {
  88. [super awakeFromNib];
  89. // Initialization code
  90. }
  91. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  92. [super setSelected:selected animated:animated];
  93. // Configure the view for the selected state
  94. }
  95. - (UILabel *)titleLabel {
  96. if (!_titleLabel) {
  97. _titleLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font(14)];
  98. }
  99. return _titleLabel;
  100. }
  101. - (UILabel *)disLabel {
  102. if (!_disLabel) {
  103. _disLabel = [UILabel createLabelTextColor:ColorFromHexStringWithAlpha(@"#959598", 1) fount:Font(14)];
  104. }
  105. return _disLabel;
  106. }
  107. - (UIImageView *)moreImageView {
  108. if (!_moreImageView) {
  109. _moreImageView = [UIImageView new];
  110. _moreImageView.image = arrowMore();
  111. }
  112. return _moreImageView;
  113. }
  114. - (UISwitch *)switchView {
  115. if (!_switchView) {
  116. _switchView = [[UISwitch alloc] init];
  117. _switchView.on = NO;
  118. _switchView.onImage = ImageNamed(@"icon_switch_active");
  119. _switchView.offImage = ImageNamed(@"icon_switch_default");
  120. _switchView.onTintColor = Switch_Select_Color;
  121. }
  122. return _switchView;
  123. }
  124. - (UIView *)lineView {
  125. if (!_lineView) {
  126. _lineView = [UIView new];;
  127. _lineView.backgroundColor = Color_line;
  128. }
  129. return _lineView;
  130. }
  131. @end