1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- //
- // YMCreateGreetingTemplateTextView.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/25.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMCreateGreetingTemplateTextView.h"
- #import "YMCreateGreetingTemplateViewModel.h"
- @interface YMCreateGreetingTemplateTextView ()
- /// 创建打招呼模板VM
- @property (nonatomic, strong) YMCreateGreetingTemplateViewModel *viewModel;
- /// 模板文本框
- @property (nonatomic, strong) YMTextView *templateTextView;
- /// 模板上限标签
- @property (nonatomic, strong) UILabel *templateLimitLb;
- @end
- @implementation YMCreateGreetingTemplateTextView
- - (void)ym_setupViews{
-
- [self addSubview:self.templateTextView];
- [self addSubview:self.templateLimitLb];
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints{
-
- [self.templateTextView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(adapt(15));
- make.left.equalTo(self).offset(adapt(15));
- make.right.equalTo(self).offset(adapt(-15));
- make.bottom.equalTo(self).offset(adapt(-15));
- make.height.mas_equalTo(adapt(150));
- }];
-
- [self.templateLimitLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self).offset(adapt(-30));
- make.bottom.equalTo(self).offset(adapt(-30));
- make.height.mas_equalTo(adapt(15));
- }];
-
- [super updateConstraints];
- }
- - (void)ym_bindViewModel:(YMCreateGreetingTemplateViewModel *)viewModel{
- if (!viewModel) {
- return;
- }
-
- _viewModel = viewModel;
-
- @weakify(self)
- [[[[RACObserve(self.viewModel, templateMaxLength) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNumber * templateMaxLength) {
- @strongify(self)
- self.templateTextView.maxLength = [templateMaxLength intValue];
- self.templateLimitLb.text = stringFormat(@"0/%ld",self.viewModel.templateMaxLength);
- }];
-
- [self.templateTextView addTextDidChangeHandler:^(YMTextView * _Nonnull textView) {
- @strongify(self)
- self.templateLimitLb.text = stringFormat(@"%ld/%ld",textView.formatText.length,self.viewModel.templateMaxLength);
- self.viewModel.templateText = textView.formatText;
- }];
-
- }
- - (YMTextView *)templateTextView {
- if (!_templateTextView) {
- _templateTextView = [[YMTextView alloc]init];
- _templateTextView.ym_textContainerInset = UIEdgeInsetsMake(adapt(10), adapt(10), adapt(35), adapt(10));
- _templateTextView.textColor = HexColorFromRGB(0x333333);
- _templateTextView.tintColor = HexColorFromRGB(0xfd7bc5);
- _templateTextView.font = LCFont(13);
- _templateTextView.placeholder = @"请输入文字内容文案";
- _templateTextView.placeholderFont = LCFont(12);
- _templateTextView.placeholderColor = HexColorFromRGB(0x9a9a9a);
- _templateTextView.minHeight = adapt(150);
- _templateTextView.backgroundColor = HexColorFromRGB(0xF6F6F6);
- _templateTextView.layer.cornerRadius = adapt(10);
- _templateTextView.layer.masksToBounds = YES;
- }
- return _templateTextView;
- }
- - (UILabel *)templateLimitLb{
- if (!_templateLimitLb) {
- _templateLimitLb = [[UILabel alloc]init];
- _templateLimitLb.font = LCFont(13);
- _templateLimitLb.textColor = HexColorFromRGB(0x9c9c9c);
- _templateLimitLb.textAlignment = NSTextAlignmentRight;
- }
- return _templateLimitLb;
- }
- @end
|