YMPersonalPageInfoCell.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // YMPersonalPageInfoCell.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/18.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMPersonalPageInfoCell.h"
  9. #import "YMPersonalPageInfoCellViewModel.h"
  10. @interface YMPersonalPageInfoCell()
  11. /// ViewModel
  12. @property (nonatomic, strong) YMPersonalPageInfoCellViewModel *viewModel;
  13. /// 基础视图
  14. @property (nonatomic, strong) UIView *baseView;
  15. /// 信息标题标签
  16. @property (nonatomic, strong) UILabel *infoTitleLb;
  17. /// 信息内容标签
  18. @property (nonatomic, strong) UILabel *infoContentLb;
  19. /// 信息复制图标
  20. @property (nonatomic, strong) UIImageView *infoCopyIcon;
  21. @end
  22. @implementation YMPersonalPageInfoCell
  23. - (void)ym_setupViews{
  24. [self.contentView addSubview:self.baseView];
  25. [self.baseView addSubview:self.infoTitleLb];
  26. [self.baseView addSubview:self.infoContentLb];
  27. [self.baseView addSubview:self.infoCopyIcon];
  28. [self setNeedsUpdateConstraints];
  29. [self updateConstraintsIfNeeded];
  30. }
  31. - (void)updateConstraints {
  32. [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.top.equalTo(self.contentView);
  34. make.left.equalTo(self.contentView);
  35. make.right.equalTo(self.contentView);
  36. make.bottom.equalTo(self.contentView);
  37. }];
  38. [self.infoTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.top.equalTo(self.baseView).offset(adapt(5));
  40. make.left.equalTo(self.baseView).offset(adapt(5));
  41. make.bottom.equalTo(self.baseView).offset(adapt(-5));
  42. }];
  43. [self.infoContentLb mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.top.equalTo(self.baseView).offset(adapt(5));
  45. make.left.equalTo(self.infoTitleLb.mas_right).offset(adapt(5));
  46. make.bottom.equalTo(self.baseView).offset(adapt(-5));
  47. }];
  48. [self.infoCopyIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.centerY.equalTo(self.baseView.mas_centerY);
  50. make.left.equalTo(self.infoContentLb.mas_right).offset(adapt(5));
  51. make.width.height.mas_equalTo(adapt(20));
  52. }];
  53. [super updateConstraints];
  54. }
  55. - (void)ym_bindViewModel:(YMPersonalPageInfoCellViewModel*)viewModel{
  56. if (!viewModel) {
  57. return;
  58. }
  59. _viewModel = viewModel;
  60. self.infoTitleLb.text = self.viewModel.infoTitle;
  61. self.infoContentLb.text = self.viewModel.infoContent;
  62. self.infoCopyIcon.hidden = self.viewModel.isHideCopy;
  63. }
  64. - (UIView *)baseView{
  65. if (!_baseView) {
  66. _baseView = [[UIView alloc]init];
  67. }
  68. return _baseView;
  69. }
  70. - (UILabel *)infoTitleLb{
  71. if (!_infoTitleLb) {
  72. _infoTitleLb = [[UILabel alloc]init];
  73. _infoTitleLb.font = LCFont(12);
  74. _infoTitleLb.textColor = HexColorFromRGB(0x737373);
  75. _infoTitleLb.textAlignment = NSTextAlignmentLeft;
  76. _infoTitleLb.text = @"****";
  77. /**
  78. *抗拉伸 setContentHuggingPriority(值越高,越不容易拉伸)
  79. */
  80. [_infoTitleLb setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
  81. /**
  82. *抗压缩 setContentCompressionResistancePriority(值越高,越不容易压缩)
  83. **/
  84. [_infoTitleLb setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
  85. }
  86. return _infoTitleLb;
  87. }
  88. - (UILabel *)infoContentLb{
  89. if (!_infoContentLb) {
  90. _infoContentLb = [[UILabel alloc]init];
  91. _infoContentLb.font = LCBoldFont(13);
  92. _infoContentLb.textColor = HexColorFromRGB(0x333333);
  93. _infoContentLb.textAlignment = NSTextAlignmentLeft;
  94. _infoContentLb.text = @"****";
  95. /**
  96. *抗拉伸 setContentHuggingPriority(值越高,越不容易拉伸)
  97. */
  98. [_infoContentLb setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
  99. /**
  100. *抗压缩 setContentCompressionResistancePriority(值越高,越不容易压缩)
  101. **/
  102. [_infoContentLb setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
  103. }
  104. return _infoContentLb;
  105. }
  106. - (UIImageView *)infoCopyIcon{
  107. if (!_infoCopyIcon) {
  108. _infoCopyIcon = [[UIImageView alloc]init];
  109. _infoCopyIcon.image = ImageByName(@"ym_personal_page_copy_icon");
  110. /**
  111. *抗拉伸 setContentHuggingPriority(值越高,越不容易拉伸)
  112. */
  113. [_infoCopyIcon setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
  114. /**
  115. *抗压缩 setContentCompressionResistancePriority(值越高,越不容易压缩)
  116. **/
  117. [_infoCopyIcon setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
  118. }
  119. return _infoCopyIcon;
  120. }
  121. @end