// // YMDynamicDetailCommentSectionView.m // MSYOUPAI // // Created by YoMi on 2024/3/22. // Copyright © 2024 MS. All rights reserved. // #import "YMDynamicDetailCommentSectionView.h" @interface YMDynamicDetailCommentSectionView () /** 分组堆叠视图*/ @property (nonatomic, strong) UIStackView *sectionStackView; /// 分组标题图标 @property (nonatomic, strong) UIImageView *sectionTitleIcon; /// 分组标题标签 @property (nonatomic, strong) UILabel *sectionTitleLb; @end @implementation YMDynamicDetailCommentSectionView - (void)ym_setupViews{ [self.contentView addSubview:self.sectionStackView]; [self.sectionStackView addArrangedSubview:self.sectionTitleIcon]; [self.sectionStackView addArrangedSubview:self.sectionTitleLb]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints{ [self.sectionStackView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView); make.left.equalTo(self.contentView).offset(adapt(10)); make.bottom.equalTo(self.contentView); }]; [self.sectionTitleIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.width.height.mas_equalTo(adapt(20)); }]; [self.sectionTitleLb mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(adapt(20)); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(id)viewModel{ if ([viewModel isKindOfClass:[NSString class]]) { self.sectionTitleLb.text = viewModel; } } - (UIStackView *)sectionStackView{ if (!_sectionStackView) { _sectionStackView = [[UIStackView alloc]init]; /** UILayoutConstraintAxisVertical 纵向 UILayoutConstraintAxisHorizontal 横向 */ _sectionStackView.axis = UILayoutConstraintAxisHorizontal; /** UIsectionStackViewAlignmentFill 将sectionStackView充满 比如label,不管文字多少,将大小按照设置的非主轴方向充满 ex: Vertical 就是水平铺满 UIsectionStackViewAlignmentLeading 在Vertical方向上生效,表示左对齐 比如label,文字自适应,如果小于非主轴方向的宽度,将不充满 UIsectionStackViewAlignmentTop 在Horizontal方向上生效,表示左对齐 比如label,文字自适应,如果小于非主轴方向的高度,将不充满 本质UIsectionStackViewAlignmentTop = UIsectionStackViewAlignmentLeading UIsectionStackViewAlignmentTrailing 在Vertical方向上生效,表示右对齐 比如label,文字自适应,如果小于非主轴方向的宽度,将不充满 UIsectionStackViewAlignmentBottom 在Horizontal方向上生效,表示右对齐 比如label,文字自适应,如果小于非主轴方向的高度,将不充满 本质UIsectionStackViewAlignmentBottom = UIsectionStackViewAlignmentTrailing UIsectionStackViewAlignmentLastBaseline 仅限于Horizontal 按照最高的一个视图的bottom对齐,最高的视图top对齐 UIsectionStackViewAlignmentCenter 中心对齐 不充满,沿主轴方向中心对齐 */ _sectionStackView.alignment = UIStackViewAlignmentCenter; _sectionStackView.spacing = adapt(5); } return _sectionStackView; } - (UIImageView *)sectionTitleIcon{ if (!_sectionTitleIcon) { _sectionTitleIcon = [[UIImageView alloc]init]; _sectionTitleIcon.image = ImageByName(@"ym_dynamic_comments_icon"); } return _sectionTitleIcon; } - (UILabel *)sectionTitleLb{ if (!_sectionTitleLb) { _sectionTitleLb = [[UILabel alloc]init]; _sectionTitleLb.font = LCFont(12); _sectionTitleLb.textColor = HexColorFromRGB(0x9c9c9c); _sectionTitleLb.text = @"评论"; _sectionTitleLb.textAlignment = NSTextAlignmentLeft; _sectionTitleLb.numberOfLines = 0; } return _sectionTitleLb; } @end