155 lines
5.6 KiB
Objective-C
155 lines
5.6 KiB
Objective-C
//
|
|
// MessageContentSkillCardView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/4/28.
|
|
//
|
|
|
|
#import "MessageContentSkillCardView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <YYText/YYText.h>
|
|
#import "HttpRequestHelper.h"
|
|
#import "AttachMentModel.h"
|
|
#import "GuildMessageModel.h"
|
|
#import "NSObject+MJExtension.h"
|
|
#import "ThemeColor.h"
|
|
#import "XCHUDTool.h"
|
|
#import "AccountInfoStorage.h"
|
|
#import "XPMineGuildViewController.h"
|
|
#import "XCCurrentVCStackManager.h"
|
|
#define MESSAGE_MAX_WIDTH 180
|
|
@interface MessageContentSkillCardView ()
|
|
///显示标题
|
|
@property (nonatomic,strong) UILabel *titleLabel;
|
|
///显示内容
|
|
@property (nonatomic,strong) YYLabel *contentLabel;
|
|
///消息的信息
|
|
@property (nonatomic,strong) GuildMessageModel *messageInfo;
|
|
@property (nonatomic,strong) AttachmentModel *attachment;
|
|
@property (nonatomic,strong) NIMMessage *message;
|
|
@end
|
|
|
|
@implementation MessageContentSkillCardView
|
|
|
|
+ (CGFloat)measureHeight:(NIMMessage *)message {
|
|
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
|
|
AttachmentModel * attach = obj.attachment;
|
|
GuildMessageModel * info = [GuildMessageModel modelWithDictionary:attach.data];
|
|
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]init];
|
|
GuildMessageLayoutModel *layout = info.layout;
|
|
for (GuildMessageLayoutInfoModel *params in layout.contents) {
|
|
if (params.content.length > 0) {
|
|
if ([params.content containsString:@"/r/n"]) {
|
|
params.content = @"\r\n";
|
|
}
|
|
NSMutableAttributedString *subAttr = [[NSMutableAttributedString alloc]initWithString:params.content];
|
|
if (params.fontSize > 0) {
|
|
[subAttr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:params.fontSize weight:params.fontBold?UIFontWeightBold:UIFontWeightRegular] range:NSMakeRange(0, subAttr.length)];
|
|
}
|
|
|
|
if (params.fontColor.length > 0) {
|
|
[subAttr addAttribute:NSForegroundColorAttributeName value:[ThemeColor colorWithHexString:params.fontColor] range:NSMakeRange(0, subAttr.length)];
|
|
}
|
|
[attr appendAttributedString:subAttr];
|
|
}
|
|
}
|
|
attr.yy_lineSpacing = 5;
|
|
CGSize maxSize = CGSizeMake(MESSAGE_MAX_WIDTH - MESSAGE_PADDING * 2, CGFLOAT_MAX);
|
|
YYTextLayout * contentLayout = [YYTextLayout layoutWithContainerSize:maxSize text:attr];
|
|
///顶部的距离 20 title的高度15 title到content的高度
|
|
CGFloat contentHeight = contentLayout.textBoundingSize.height+ 20 + 15 + MESSAGE_PADDING * 4;
|
|
return contentHeight + CONTENT_PADDING_V_TOTAL;
|
|
}
|
|
|
|
- (void)initSubViews {
|
|
[super initSubViews];
|
|
[self.backView addSubview:self.titleLabel];
|
|
[self.backView addSubview:self.contentLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[super initSubViewConstraints];
|
|
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(MESSAGE_MAX_WIDTH);
|
|
make.bottom.mas_equalTo(self.contentLabel.mas_bottom);
|
|
}];
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self.backView);
|
|
make.top.mas_equalTo(self.backView).offset(MESSAGE_PADDING);
|
|
}];
|
|
|
|
[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.left.mas_equalTo(self.backView);
|
|
make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(MESSAGE_PADDING);
|
|
make.height.mas_equalTo(15);
|
|
}];
|
|
}
|
|
|
|
- (void)render:(NIMMessage *)message {
|
|
self.message = message;
|
|
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
|
|
AttachmentModel * attach = obj.attachment;
|
|
self.attachment = attach;
|
|
GuildMessageModel * info= [GuildMessageModel modelWithDictionary:attach.data];
|
|
self.messageInfo = info;
|
|
self.titleLabel.text = info.layout.title.content;
|
|
self.titleLabel.font = [UIFont systemFontOfSize:info.layout.title.fontSize weight:info.layout.title.fontBold?UIFontWeightBold:UIFontWeightRegular];
|
|
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]init];
|
|
GuildMessageLayoutModel *layout = info.layout;
|
|
for (GuildMessageLayoutInfoModel *params in layout.contents) {
|
|
if (params.content.length > 0) {
|
|
if ([params.content containsString:@"/r/n"]) {
|
|
params.content = @"\r\n";
|
|
}
|
|
NSMutableAttributedString *subAttr = [[NSMutableAttributedString alloc]initWithString:params.content];
|
|
if (params.fontSize > 0) {
|
|
[subAttr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:params.fontSize weight:params.fontBold?UIFontWeightBold:UIFontWeightRegular] range:NSMakeRange(0, subAttr.length)];
|
|
}
|
|
|
|
if (params.fontColor.length > 0) {
|
|
[subAttr addAttribute:NSForegroundColorAttributeName value:[ThemeColor colorWithHexString:params.fontColor] range:NSMakeRange(0, subAttr.length)];
|
|
}
|
|
|
|
if (params.routertype > 0) {
|
|
|
|
}
|
|
|
|
[attr appendAttributedString:subAttr];
|
|
|
|
}
|
|
}
|
|
attr.yy_lineSpacing = 5;
|
|
self.contentLabel.attributedText = attr;
|
|
self.contentLabel.textAlignment = NSTextAlignmentCenter;
|
|
CGSize maxSize = CGSizeMake(MESSAGE_MAX_WIDTH - MESSAGE_PADDING * 2, CGFLOAT_MAX);
|
|
YYTextLayout * contentLayout = [YYTextLayout layoutWithContainerSize:maxSize text:attr];
|
|
CGFloat contentHeight = contentLayout.textBoundingSize.height + 5;
|
|
///顶部的距离 20 title的高度15 title到content的高度15
|
|
[self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(contentHeight);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.textAlignment= NSTextAlignmentCenter;
|
|
_titleLabel.font = [UIFont systemFontOfSize:14];
|
|
_titleLabel.textColor = [ThemeColor mainTextColor];
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (YYLabel *)contentLabel {
|
|
if (!_contentLabel) {
|
|
_contentLabel = [[YYLabel alloc] init];
|
|
_contentLabel.numberOfLines = 0;
|
|
}
|
|
return _contentLabel;
|
|
}
|
|
@end
|