XYVoiceRoomCreateTableViewCell.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // XYVoiceRoomCreateTableViewCell.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/7/7.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYVoiceRoomCreateTableViewCell.h"
  9. #import "XYVoiceRoomCreateCellModel.h"
  10. @interface XYVoiceRoomCreateTableViewCell ()
  11. @property (nonatomic, strong) UILabel *titleLabel;
  12. @property (nonatomic, strong) UITextField *textField;
  13. @property (nonatomic, strong) UIImageView *moreImageView;
  14. @property (nonatomic, strong) UIView *line;
  15. @property (nonatomic, strong) NSIndexPath *indexPath;
  16. @end
  17. @implementation XYVoiceRoomCreateTableViewCell
  18. #pragma mark — Public
  19. + (instancetype)cellWithTableView:(UITableView *)tableView
  20. {
  21. static NSString *ID = @"XYVoiceRoomCreateTableViewCell";
  22. XYVoiceRoomCreateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  23. if (cell == nil) {
  24. cell = [[XYVoiceRoomCreateTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
  25. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  26. }
  27. return cell;
  28. }
  29. - (void)configureModel:(XYVoiceRoomCreateCellModel *)model
  30. {
  31. self.titleLabel.text = model.title;
  32. self.textField.text = model.content;
  33. self.textField.placeholder = model.placeholder;
  34. self.moreImageView.hidden = !model.isShowMore;
  35. self.line.hidden = !model.isShowBottomLine;
  36. self.textField.userInteractionEnabled = model.isInput;
  37. }
  38. - (void)setIndexPath:(NSIndexPath *)indexPath rowsInSection:(NSInteger)rows {
  39. self.indexPath = self.indexPath;
  40. }
  41. #pragma mark — Action
  42. - (void)textFieldChangeText:(UITextField *)textFiled {
  43. if (self.delegate && [self.delegate respondsToSelector:@selector(textChangeWithText:atIndexPath:)]) {
  44. [self.delegate textChangeWithText:textFiled.text atIndexPath:self.indexPath];
  45. }
  46. }
  47. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  48. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  49. [self _setup];
  50. [self _setupSubViews];
  51. [self _makeSubViewsConstraint];
  52. }
  53. return self;
  54. }
  55. #pragma mark - 配置属性
  56. - (void)_setup {
  57. }
  58. #pragma mark - 设置子控件
  59. - (void)_setupSubViews {
  60. [self.contentView addSubview:self.titleLabel];
  61. [self.contentView addSubview:self.textField];
  62. [self.contentView addSubview:self.moreImageView];
  63. [self.contentView addSubview:self.line];
  64. }
  65. #pragma mark - 布局子控件
  66. - (void)_makeSubViewsConstraint {
  67. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.left.equalTo(self.contentView).offset(22.0f);
  69. make.centerY.equalTo(self.contentView);
  70. make.width.equalTo(@56.0f);
  71. }];
  72. [self.moreImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.right.equalTo(self.contentView).offset(-16.0f);
  74. make.centerY.equalTo(self.contentView);
  75. make.width.equalTo(@5.0f);
  76. make.height.equalTo(@10.0f);
  77. }];
  78. [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.left.equalTo(self.titleLabel.mas_right).offset(12.0f);
  80. make.centerY.equalTo(self.contentView);
  81. make.right.equalTo(self.moreImageView.mas_left).offset(-10.0f);
  82. }];
  83. [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.left.equalTo(self.contentView).offset(20.0f);
  85. make.bottom.right.equalTo(self.contentView);
  86. make.height.equalTo(@(LINE_HEIGHT));
  87. }];
  88. }
  89. #pragma mark - Getter/Setter
  90. - (UILabel *)titleLabel {
  91. if (!_titleLabel) {
  92. _titleLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font_B(14)];
  93. }
  94. return _titleLabel;
  95. }
  96. - (UITextField *)textField {
  97. if (!_textField) {
  98. _textField = [[UITextField alloc] init];
  99. _textField.font = Font(14);
  100. _textField.textColor = Color_TextFont;
  101. _textField.userInteractionEnabled = NO;
  102. [_textField addTarget:self action:@selector(textFieldChangeText:) forControlEvents:UIControlEventEditingChanged];
  103. }
  104. return _textField;
  105. }
  106. - (UIImageView *)moreImageView {
  107. if (!_moreImageView) {
  108. _moreImageView = [UIImageView new];
  109. _moreImageView.image = arrowMore();
  110. }
  111. return _moreImageView;
  112. }
  113. - (UIView *)line {
  114. if (!_line) {
  115. _line = [UIView new];
  116. _line.backgroundColor = Color_line;
  117. }
  118. return _line;
  119. }
  120. @end