12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- //
- // YMDynamicMessagesCellViewModel.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/3/21.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMDynamicMessagesCellViewModel.h"
- #import "YMDynamicMessagesModel.h"
- @interface YMDynamicMessagesCellViewModel ()
- /// 动态Id
- @property (nonatomic, assign, readwrite) NSInteger dynamicId;
- /// 用户Id
- @property (nonatomic, assign, readwrite) NSInteger userId;
- /// 用户头像
- @property (nonatomic, strong, readwrite) NSString *userAvatar;
- /// 动态消息内容
- @property (nonatomic, strong, readwrite) NSAttributedString *dynamicMessagesContent;
- /// 动态消息日期
- @property (nonatomic, strong, readwrite) NSString *dynamicMessagesDate;
- @end
- @implementation YMDynamicMessagesCellViewModel
- - (void)ym_initialize{
- [super ym_initialize];
- if ([self.params[ParamsModel] isKindOfClass:[YMDynamicMessagesModel class]]) {
- YMDynamicMessagesModel *model = self.params[ParamsModel];
- self.dynamicId = model.dynamic_id;
- self.userId = model.from_user_id;
- self.userAvatar = model.from_user_avatar;
- NSString *content = @"";
- if (model.is_delete == 1) {
- content = @"评论已被删除";
- } else {
-
- switch (model.is_type) {
- case 1:
- {
- content = model.content;
- }
- break;
- case 2:
- {
- content = stringFormat(@"%@回复了你:%@",model.from_user_nickname,model.content);
- }
- break;
- case 3:
- {
- content = stringFormat(@"%@评论了你:%@",model.from_user_nickname,model.content);
- }
- break;
- default:
- break;
- }
- NSMutableAttributedString *dynamicMessagesContentAttributed = [[NSMutableAttributedString alloc]initWithString:content];
- dynamicMessagesContentAttributed.yy_font = LCFont(13);
- dynamicMessagesContentAttributed.yy_color = HexColorFromRGB(0x333333);
- dynamicMessagesContentAttributed.yy_alignment = NSTextAlignmentLeft;
- dynamicMessagesContentAttributed.yy_lineSpacing = 5;
- [dynamicMessagesContentAttributed yy_setColor:HexColorFromRGB(0x7c69fe) range:[content rangeOfString:model.from_user_nickname]];
- self.dynamicMessagesContent = dynamicMessagesContentAttributed;
- }
-
- self.dynamicMessagesDate = model.create_time;
-
- }
-
- }
- @end
|