YMDynamicDetailCommentSectionView.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // YMDynamicDetailCommentSectionView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/22.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMDynamicDetailCommentSectionView.h"
  9. @interface YMDynamicDetailCommentSectionView ()
  10. /** 分组堆叠视图*/
  11. @property (nonatomic, strong) UIStackView *sectionStackView;
  12. /// 分组标题图标
  13. @property (nonatomic, strong) UIImageView *sectionTitleIcon;
  14. /// 分组标题标签
  15. @property (nonatomic, strong) UILabel *sectionTitleLb;
  16. @end
  17. @implementation YMDynamicDetailCommentSectionView
  18. - (void)ym_setupViews{
  19. [self.contentView addSubview:self.sectionStackView];
  20. [self.sectionStackView addArrangedSubview:self.sectionTitleIcon];
  21. [self.sectionStackView addArrangedSubview:self.sectionTitleLb];
  22. [self setNeedsUpdateConstraints];
  23. [self updateConstraintsIfNeeded];
  24. }
  25. - (void)updateConstraints{
  26. [self.sectionStackView mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.top.equalTo(self.contentView);
  28. make.left.equalTo(self.contentView).offset(adapt(10));
  29. make.bottom.equalTo(self.contentView);
  30. }];
  31. [self.sectionTitleIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.width.height.mas_equalTo(adapt(20));
  33. }];
  34. [self.sectionTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.height.mas_equalTo(adapt(20));
  36. }];
  37. [super updateConstraints];
  38. }
  39. - (void)ym_bindViewModel:(id)viewModel{
  40. if ([viewModel isKindOfClass:[NSString class]]) {
  41. self.sectionTitleLb.text = viewModel;
  42. }
  43. }
  44. - (UIStackView *)sectionStackView{
  45. if (!_sectionStackView) {
  46. _sectionStackView = [[UIStackView alloc]init];
  47. /**
  48. UILayoutConstraintAxisVertical 纵向
  49. UILayoutConstraintAxisHorizontal 横向
  50. */
  51. _sectionStackView.axis = UILayoutConstraintAxisHorizontal;
  52. /**
  53. UIsectionStackViewAlignmentFill 将sectionStackView充满
  54. 比如label,不管文字多少,将大小按照设置的非主轴方向充满
  55. ex: Vertical 就是水平铺满
  56. UIsectionStackViewAlignmentLeading 在Vertical方向上生效,表示左对齐
  57. 比如label,文字自适应,如果小于非主轴方向的宽度,将不充满
  58. UIsectionStackViewAlignmentTop 在Horizontal方向上生效,表示左对齐
  59. 比如label,文字自适应,如果小于非主轴方向的高度,将不充满
  60. 本质UIsectionStackViewAlignmentTop = UIsectionStackViewAlignmentLeading
  61. UIsectionStackViewAlignmentTrailing 在Vertical方向上生效,表示右对齐
  62. 比如label,文字自适应,如果小于非主轴方向的宽度,将不充满
  63. UIsectionStackViewAlignmentBottom 在Horizontal方向上生效,表示右对齐
  64. 比如label,文字自适应,如果小于非主轴方向的高度,将不充满
  65. 本质UIsectionStackViewAlignmentBottom = UIsectionStackViewAlignmentTrailing
  66. UIsectionStackViewAlignmentLastBaseline 仅限于Horizontal
  67. 按照最高的一个视图的bottom对齐,最高的视图top对齐
  68. UIsectionStackViewAlignmentCenter 中心对齐
  69. 不充满,沿主轴方向中心对齐
  70. */
  71. _sectionStackView.alignment = UIStackViewAlignmentCenter;
  72. _sectionStackView.spacing = adapt(5);
  73. }
  74. return _sectionStackView;
  75. }
  76. - (UIImageView *)sectionTitleIcon{
  77. if (!_sectionTitleIcon) {
  78. _sectionTitleIcon = [[UIImageView alloc]init];
  79. _sectionTitleIcon.image = ImageByName(@"ym_dynamic_comments_icon");
  80. }
  81. return _sectionTitleIcon;
  82. }
  83. - (UILabel *)sectionTitleLb{
  84. if (!_sectionTitleLb) {
  85. _sectionTitleLb = [[UILabel alloc]init];
  86. _sectionTitleLb.font = LCFont(12);
  87. _sectionTitleLb.textColor = HexColorFromRGB(0x9c9c9c);
  88. _sectionTitleLb.text = @"评论";
  89. _sectionTitleLb.textAlignment = NSTextAlignmentLeft;
  90. _sectionTitleLb.numberOfLines = 0;
  91. }
  92. return _sectionTitleLb;
  93. }
  94. @end