YMFeesSettingNotesView.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // YMFeesSettingNotesCell.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/24.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMFeesSettingNotesView.h"
  9. #import "YMFeesSettingViewModel.h"
  10. @interface YMFeesSettingNotesView ()
  11. /// 收费设置VM
  12. @property (nonatomic, strong) YMFeesSettingViewModel *viewModel;
  13. /// 说明提示标签
  14. @property (nonatomic, strong) YYLabel *notesTipsLb;
  15. @end
  16. @implementation YMFeesSettingNotesView
  17. - (void)ym_setupViews{
  18. [self addSubview:self.notesTipsLb];
  19. [self setNeedsUpdateConstraints];
  20. [self updateConstraintsIfNeeded];
  21. }
  22. - (void)updateConstraints{
  23. [self.notesTipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  24. make.top.equalTo(self).offset(adapt(10));
  25. make.left.equalTo(self).offset(adapt(15));
  26. make.right.equalTo(self).offset(adapt(-15));
  27. make.bottom.equalTo(self).offset(adapt(-10));
  28. }];
  29. [super updateConstraints];
  30. }
  31. - (void)ym_bindViewModel:(YMFeesSettingViewModel *)viewModel{
  32. if (!viewModel) {
  33. return;
  34. }
  35. _viewModel = viewModel;
  36. @weakify(self)
  37. [[[[RACObserve(self.viewModel, notesTipsAttributed) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSAttributedString * notesTipsAttributed) {
  38. @strongify(self)
  39. self.notesTipsLb.attributedText = notesTipsAttributed;
  40. CGSize introSize = CGSizeMake(kFrameWidth - adapt(15)*2, CGFLOAT_MAX);
  41. YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:introSize text:viewModel.notesTipsAttributed];
  42. self.notesTipsLb.textLayout = layout;
  43. CGFloat notesTipsLbHeight = layout.textBoundingSize.height;
  44. [self.notesTipsLb mas_updateConstraints:^(MASConstraintMaker *make) {
  45. make.height.mas_equalTo(notesTipsLbHeight);
  46. }];
  47. if (self.notesViewHeightBlock) {
  48. self.notesViewHeightBlock(adapt(10) + notesTipsLbHeight + adapt(10));
  49. }
  50. }];
  51. }
  52. - (YYLabel *)notesTipsLb{
  53. if (!_notesTipsLb) {
  54. _notesTipsLb = [[YYLabel alloc]init];
  55. _notesTipsLb.font = LCFont(11);
  56. _notesTipsLb.textColor = HexColorFromRGB(0x9c9c9c);
  57. _notesTipsLb.textAlignment = NSTextAlignmentLeft;
  58. _notesTipsLb.numberOfLines = 0;
  59. }
  60. return _notesTipsLb;
  61. }
  62. @end