YMCreateGreetingTemplateTextView.m 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // YMCreateGreetingTemplateTextView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/25.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMCreateGreetingTemplateTextView.h"
  9. #import "YMCreateGreetingTemplateViewModel.h"
  10. @interface YMCreateGreetingTemplateTextView ()
  11. /// 创建打招呼模板VM
  12. @property (nonatomic, strong) YMCreateGreetingTemplateViewModel *viewModel;
  13. /// 模板文本框
  14. @property (nonatomic, strong) YMTextView *templateTextView;
  15. /// 模板上限标签
  16. @property (nonatomic, strong) UILabel *templateLimitLb;
  17. @end
  18. @implementation YMCreateGreetingTemplateTextView
  19. - (void)ym_setupViews{
  20. [self addSubview:self.templateTextView];
  21. [self addSubview:self.templateLimitLb];
  22. [self setNeedsUpdateConstraints];
  23. [self updateConstraintsIfNeeded];
  24. }
  25. - (void)updateConstraints{
  26. [self.templateTextView mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.top.equalTo(self).offset(adapt(15));
  28. make.left.equalTo(self).offset(adapt(15));
  29. make.right.equalTo(self).offset(adapt(-15));
  30. make.bottom.equalTo(self).offset(adapt(-15));
  31. make.height.mas_equalTo(adapt(150));
  32. }];
  33. [self.templateLimitLb mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.right.equalTo(self).offset(adapt(-30));
  35. make.bottom.equalTo(self).offset(adapt(-30));
  36. make.height.mas_equalTo(adapt(15));
  37. }];
  38. [super updateConstraints];
  39. }
  40. - (void)ym_bindViewModel:(YMCreateGreetingTemplateViewModel *)viewModel{
  41. if (!viewModel) {
  42. return;
  43. }
  44. _viewModel = viewModel;
  45. @weakify(self)
  46. [[[[RACObserve(self.viewModel, templateMaxLength) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNumber * templateMaxLength) {
  47. @strongify(self)
  48. self.templateTextView.maxLength = [templateMaxLength intValue];
  49. self.templateLimitLb.text = stringFormat(@"0/%ld",self.viewModel.templateMaxLength);
  50. }];
  51. [self.templateTextView addTextDidChangeHandler:^(YMTextView * _Nonnull textView) {
  52. @strongify(self)
  53. self.templateLimitLb.text = stringFormat(@"%ld/%ld",textView.formatText.length,self.viewModel.templateMaxLength);
  54. self.viewModel.templateText = textView.formatText;
  55. }];
  56. }
  57. - (YMTextView *)templateTextView {
  58. if (!_templateTextView) {
  59. _templateTextView = [[YMTextView alloc]init];
  60. _templateTextView.ym_textContainerInset = UIEdgeInsetsMake(adapt(10), adapt(10), adapt(35), adapt(10));
  61. _templateTextView.textColor = HexColorFromRGB(0x333333);
  62. _templateTextView.tintColor = HexColorFromRGB(0xfd7bc5);
  63. _templateTextView.font = LCFont(13);
  64. _templateTextView.placeholder = @"请输入文字内容文案";
  65. _templateTextView.placeholderFont = LCFont(12);
  66. _templateTextView.placeholderColor = HexColorFromRGB(0x9a9a9a);
  67. _templateTextView.minHeight = adapt(150);
  68. _templateTextView.backgroundColor = HexColorFromRGB(0xF6F6F6);
  69. _templateTextView.layer.cornerRadius = adapt(10);
  70. _templateTextView.layer.masksToBounds = YES;
  71. }
  72. return _templateTextView;
  73. }
  74. - (UILabel *)templateLimitLb{
  75. if (!_templateLimitLb) {
  76. _templateLimitLb = [[UILabel alloc]init];
  77. _templateLimitLb.font = LCFont(13);
  78. _templateLimitLb.textColor = HexColorFromRGB(0x9c9c9c);
  79. _templateLimitLb.textAlignment = NSTextAlignmentRight;
  80. }
  81. return _templateLimitLb;
  82. }
  83. @end