110 lines
3.3 KiB
Objective-C
110 lines
3.3 KiB
Objective-C
//
|
|
// MessageContentMonentsAutoView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/8/26.
|
|
//
|
|
|
|
#import "MessageContentMonentsAutoView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "NSObject+MJExtension.h"
|
|
#import "ThemeColor.h"
|
|
///Model
|
|
#import "GuildMessageModel.h"
|
|
@interface MessageContentMonentsAutoView ()
|
|
|
|
@property (nonatomic, strong) UILabel *titleLabel; // 标题
|
|
@property (nonatomic, strong) UILabel *timeLabel; // 时间
|
|
@property (nonatomic, strong) UILabel *messageLabel; // 内容
|
|
@end
|
|
|
|
@implementation MessageContentMonentsAutoView
|
|
|
|
+ (CGFloat)measureHeight:(NIMMessage *)message {
|
|
return (CONTENT_PADDING_V_TOTAL + 144);
|
|
}
|
|
|
|
- (void)initSubViews {
|
|
[super initSubViews];
|
|
[self addSubview:self.backView];
|
|
|
|
[self.backView addSubview:self.titleLabel];
|
|
[self.backView addSubview:self.timeLabel];
|
|
[self.backView addSubview:self.messageLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[super initSubViewConstraints];
|
|
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(200, 144));
|
|
}];
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(14.5);
|
|
make.top.mas_equalTo(10);
|
|
}];
|
|
|
|
[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(-14.5);
|
|
make.centerY.mas_equalTo(self.titleLabel);
|
|
}];
|
|
|
|
[self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self).inset(14.5);
|
|
make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(12.5);
|
|
}];
|
|
}
|
|
|
|
- (void)render:(NIMMessage *)message {
|
|
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
|
|
AttachmentModel * attach = obj.attachment;
|
|
NSDictionary * dic = attach.data;
|
|
GuildMessageModel *model = [GuildMessageModel modelWithDictionary:dic];
|
|
GuildMessageLayoutModel * layout = model.layout;
|
|
if (layout) {
|
|
self.titleLabel.text = layout.title.content;
|
|
self.timeLabel.text = layout.time.content;
|
|
NSMutableAttributedString *msgString = [[NSMutableAttributedString alloc] init];
|
|
|
|
[layout.contents enumerateObjectsUsingBlock:^(GuildMessageLayoutInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:obj.content];
|
|
[string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:obj.fontSize] range:NSMakeRange(0, string.length)];
|
|
[string addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x333333) range:NSMakeRange(0, string.length)];
|
|
[msgString appendAttributedString:string];
|
|
}];
|
|
self.messageLabel.attributedText = msgString;
|
|
}
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.textColor = UIColorFromRGB(0x333333);
|
|
_titleLabel.font = [UIFont boldSystemFontOfSize:15];
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (UILabel *)timeLabel {
|
|
if (!_timeLabel) {
|
|
_timeLabel = [[UILabel alloc] init];
|
|
_timeLabel.textColor = UIColorFromRGB(0x999999);
|
|
_timeLabel.font = [UIFont systemFontOfSize:12];
|
|
_timeLabel.textAlignment = NSTextAlignmentRight;
|
|
}
|
|
return _timeLabel;
|
|
}
|
|
|
|
- (UILabel *)messageLabel {
|
|
if (!_messageLabel) {
|
|
_messageLabel = [[UILabel alloc] init];
|
|
_messageLabel.textColor = UIColorFromRGB(0x333333);
|
|
_messageLabel.font = [UIFont systemFontOfSize:14];
|
|
_messageLabel.numberOfLines = 0;
|
|
}
|
|
return _messageLabel;
|
|
}
|
|
@end
|