123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- //
- // XYVoiceRoomCreateTableViewCell.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/7/7.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYVoiceRoomCreateTableViewCell.h"
- #import "XYVoiceRoomCreateCellModel.h"
- @interface XYVoiceRoomCreateTableViewCell ()
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UITextField *textField;
- @property (nonatomic, strong) UIImageView *moreImageView;
- @property (nonatomic, strong) UIView *line;
- @property (nonatomic, strong) NSIndexPath *indexPath;
- @end
- @implementation XYVoiceRoomCreateTableViewCell
- #pragma mark — Public
- + (instancetype)cellWithTableView:(UITableView *)tableView
- {
- static NSString *ID = @"XYVoiceRoomCreateTableViewCell";
- XYVoiceRoomCreateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
- if (cell == nil) {
- cell = [[XYVoiceRoomCreateTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- return cell;
- }
- - (void)configureModel:(XYVoiceRoomCreateCellModel *)model
- {
- self.titleLabel.text = model.title;
- self.textField.text = model.content;
- self.textField.placeholder = model.placeholder;
- self.moreImageView.hidden = !model.isShowMore;
- self.line.hidden = !model.isShowBottomLine;
- self.textField.userInteractionEnabled = model.isInput;
- }
- - (void)setIndexPath:(NSIndexPath *)indexPath rowsInSection:(NSInteger)rows {
- self.indexPath = self.indexPath;
- }
- #pragma mark — Action
- - (void)textFieldChangeText:(UITextField *)textFiled {
- if (self.delegate && [self.delegate respondsToSelector:@selector(textChangeWithText:atIndexPath:)]) {
- [self.delegate textChangeWithText:textFiled.text atIndexPath:self.indexPath];
- }
- }
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
- [self _setup];
- [self _setupSubViews];
- [self _makeSubViewsConstraint];
- }
- return self;
- }
- #pragma mark - 配置属性
- - (void)_setup {
-
- }
- #pragma mark - 设置子控件
- - (void)_setupSubViews {
- [self.contentView addSubview:self.titleLabel];
- [self.contentView addSubview:self.textField];
- [self.contentView addSubview:self.moreImageView];
- [self.contentView addSubview:self.line];
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraint {
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(22.0f);
- make.centerY.equalTo(self.contentView);
- make.width.equalTo(@56.0f);
- }];
- [self.moreImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView).offset(-16.0f);
- make.centerY.equalTo(self.contentView);
- make.width.equalTo(@5.0f);
- make.height.equalTo(@10.0f);
- }];
- [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.titleLabel.mas_right).offset(12.0f);
- make.centerY.equalTo(self.contentView);
- make.right.equalTo(self.moreImageView.mas_left).offset(-10.0f);
- }];
- [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(20.0f);
- make.bottom.right.equalTo(self.contentView);
- make.height.equalTo(@(LINE_HEIGHT));
- }];
- }
- #pragma mark - Getter/Setter
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font_B(14)];
- }
- return _titleLabel;
- }
- - (UITextField *)textField {
- if (!_textField) {
- _textField = [[UITextField alloc] init];
- _textField.font = Font(14);
- _textField.textColor = Color_TextFont;
- _textField.userInteractionEnabled = NO;
- [_textField addTarget:self action:@selector(textFieldChangeText:) forControlEvents:UIControlEventEditingChanged];
- }
- return _textField;
- }
- - (UIImageView *)moreImageView {
- if (!_moreImageView) {
- _moreImageView = [UIImageView new];
- _moreImageView.image = arrowMore();
- }
- return _moreImageView;
- }
- - (UIView *)line {
- if (!_line) {
- _line = [UIView new];
- _line.backgroundColor = Color_line;
- }
- return _line;
- }
- @end
|