XYModifyInputTextTableViewCell.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // XYModifyInputTextTableViewCell.m
  3. // Timi
  4. //
  5. // Created by gy on 2021/3/4.
  6. //
  7. #import "XYModifyInputTextTableViewCell.h"
  8. #import "UITextView+KCPlaceHolder.h"
  9. #import "XYModifyUserInfoListModel.h"
  10. @interface XYModifyInputTextTableViewCell ()<UITextViewDelegate>
  11. @property (nonatomic, strong) UITextView *textView;
  12. @end
  13. @implementation XYModifyInputTextTableViewCell
  14. #pragma mark - Public Method
  15. + (instancetype)cellWithTableView:(UITableView *)tableView {
  16. static NSString * const cellId = @"XYModifyInputTextTableViewCell";
  17. XYModifyInputTextTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
  18. if (cell == nil) {
  19. cell = [[XYModifyInputTextTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
  20. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  21. }
  22. return cell;
  23. }
  24. - (void)configureModel:(XYModifyUserInfoListModel *)model {
  25. self.textView.text = model.itemValue;
  26. }
  27. #pragma mark - 初始化
  28. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  29. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  30. // 初始化
  31. [self _setup];
  32. }
  33. return self;
  34. }
  35. #pragma mark - 事件处理Or辅助方法
  36. - (void)saveAction {
  37. if (StringIsEmpty(self.textView.text)) {
  38. [SVProgressHUD showInfoWithStatus:kLocalizedString(@"不能为空")];
  39. return;
  40. }
  41. [self.textView resignFirstResponder];
  42. [self.delegate XYModifyInputTextTableViewCellAction:self.textView.text];
  43. }
  44. #pragma mark - Private Method
  45. - (void)_setup{
  46. self.backgroundColor = Color_White;
  47. [self textView];
  48. }
  49. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
  50. if ([text isEqualToString:@"\n"]){
  51. [self saveAction];
  52. return NO;
  53. }
  54. return YES;
  55. }
  56. - (UITextView *)textView{
  57. if (_textView == nil) {
  58. _textView = [UITextView new];
  59. _textView.kc_placeHolder = kLocalizedString(@"填写个性签名~");
  60. _textView.kc_maxWordInput = [NSNumber numberWithInt:1000];
  61. _textView.kc_placeHolderColor = UIColorFromRGB(0xCCCCCC);
  62. _textView.kc_placeHolderFont = [UIFont fontWithName:kPFSCFont size:12];
  63. _textView.backgroundColor = [UIColor clearColor];
  64. _textView.returnKeyType = UIReturnKeySend;
  65. _textView.delegate = self ;
  66. _textView.textColor = UIColorFromRGB(0x303133);
  67. _textView.font = RegularFont(12);
  68. _textView.returnKeyType = UIReturnKeyDone;
  69. [self.contentView addSubview:_textView];
  70. [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.left.equalTo(self.contentView.mas_left).offset(20);
  72. make.right.equalTo(self.contentView.mas_right).offset(-20);
  73. make.top.equalTo(self.contentView.mas_top).offset(10);
  74. make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
  75. }];
  76. }
  77. return _textView ;
  78. }
  79. - (void)awakeFromNib {
  80. [super awakeFromNib];
  81. // Initialization code
  82. }
  83. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  84. [super setSelected:selected animated:animated];
  85. // Configure the view for the selected state
  86. }
  87. @end