// // YMDynamicMessagesCell.m // MSYOUPAI // // Created by YoMi on 2024/3/21. // Copyright © 2024 MS. All rights reserved. // #import "YMDynamicMessagesCell.h" #import "YMDynamicMessagesCellViewModel.h" @interface YMDynamicMessagesCell () /// ViewModel @property (nonatomic, strong) YMDynamicMessagesCellViewModel *viewModel; /// 基础视图 @property (nonatomic, strong) UIView *baseView; /// 用户头像视图 @property (nonatomic, strong) UIImageView *userAvatarView; /// 动态消息内容标签 @property (nonatomic, strong) UILabel *dynamicMessagesContentLb; /// 动态消息日期标签 @property (nonatomic, strong) UILabel *dynamicMessagesDateLb; @end @implementation YMDynamicMessagesCell - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (void)ym_setupViews{ self.contentView.backgroundColor = UIColor.clearColor; self.backgroundColor = UIColor.clearColor; [self.contentView addSubview:self.baseView]; [self.baseView addSubview:self.userAvatarView]; [self.baseView addSubview:self.dynamicMessagesContentLb]; [self.baseView addSubview:self.dynamicMessagesDateLb]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints { [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView); make.left.equalTo(self.contentView); make.right.equalTo(self.contentView); make.bottom.equalTo(self.contentView); }]; [self.userAvatarView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.baseView).offset(adapt(15)); make.left.equalTo(self.baseView).offset(adapt(15)); make.width.height.mas_equalTo(adapt(50)); }]; [self.dynamicMessagesContentLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.userAvatarView.mas_top); make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10)); }]; [self.dynamicMessagesDateLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.userAvatarView.mas_bottom).offset(adapt(5)); make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10)); make.bottom.equalTo(self.baseView).offset(adapt(-15)).priorityHigh(); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMDynamicMessagesCellViewModel*)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; [self.userAvatarView sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.viewModel.userAvatar]]; self.dynamicMessagesContentLb.attributedText = self.viewModel.dynamicMessagesContent; self.dynamicMessagesDateLb.text = self.viewModel.dynamicMessagesDate; } - (UIView *)baseView{ if (!_baseView) { _baseView = [[UIView alloc]init]; _baseView.backgroundColor = HexColorFromRGB(0xFFFFFF); } return _baseView; } - (UIImageView *)userAvatarView{ if (!_userAvatarView) { _userAvatarView = [[UIImageView alloc]init]; _userAvatarView.backgroundColor = UIColor.lightGrayColor; _userAvatarView.contentMode = UIViewContentModeScaleAspectFill; _userAvatarView.layer.cornerRadius = adapt(5); _userAvatarView.clipsToBounds = YES; _userAvatarView.userInteractionEnabled = YES; WS(weakSelf) UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init]; [_userAvatarView addGestureRecognizer:tap]; [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { [weakSelf.viewModel.gotoPersonalPageSubject sendNext:@(weakSelf.viewModel.userId)]; }]; } return _userAvatarView; } - (UILabel *)dynamicMessagesContentLb{ if (!_dynamicMessagesContentLb) { _dynamicMessagesContentLb = [[UILabel alloc]init]; _dynamicMessagesContentLb.font = LCFont(13); _dynamicMessagesContentLb.textColor = HexColorFromRGB(0x333333); _dynamicMessagesContentLb.textAlignment = NSTextAlignmentLeft; _dynamicMessagesContentLb.text = @"******"; _dynamicMessagesContentLb.numberOfLines = 3; } return _dynamicMessagesContentLb; } - (UILabel *)dynamicMessagesDateLb{ if (!_dynamicMessagesDateLb) { _dynamicMessagesDateLb = [[UILabel alloc]init]; _dynamicMessagesDateLb.font = LCFont(12); _dynamicMessagesDateLb.textColor = HexColorFromRGB(0x9c9c9c); _dynamicMessagesDateLb.textAlignment = NSTextAlignmentLeft; _dynamicMessagesDateLb.text = @"******"; } return _dynamicMessagesDateLb; } @end