CNLiveMessageFrame.m
1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// CNLiveMessageFrame.m
// CNLiveSettingModule
//
// Created by open on 2018/9/1.
// Copyright © 2018年 cnlive. All rights reserved.
//
#import "CNLiveMessageFrame.h"
#import "CNLiveMessageModel.h"
#import "QMUIKit.h"
#import "CNLiveBaseKit.h"
@implementation CNLiveMessageFrame
- (void)setMessage:(CNLiveMessageModel *)message{
_message = message;
// 1.计算头像位置
CGFloat iconX = ChatMargin;//头像边距
if ([_message.fromMe isEqualToString:@"1"]) {
iconX = SCREEN_WIDTH - ChatMargin - ChatIconWH;//头像坐标X
}
CGFloat iconY = ChatContentTop;//头像坐标Y
_iconFrame = CGRectMake(iconX, iconY, ChatIconWH, ChatIconWH);
// 2.计算内容位置
CGFloat contentX = ChatIconWH+ChatMargin*2;
CGFloat contentY = iconY;
CGSize maxSize = CGSizeMake(SCREEN_WIDTH-ChatIconWH*2-ChatMargin*2-(ChatContentLeft + ChatContentRight), CGFLOAT_MAX);
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
[paragraphStyle setLineSpacing:ChatLineSpacing];
CGSize contentSize = [_message.content boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:UIFontCNMake(15),NSParagraphStyleAttributeName:paragraphStyle} context:nil].size;
if ([_message.fromMe isEqualToString:@"1"]){
contentX = iconX - contentSize.width - ChatContentLeft - ChatContentRight - ChatMargin;
}
CGFloat h = 0;
if (contentSize.height + ChatContentTop + ChatContentBottom < ChatIconWH) {
h = ChatIconWH;
}
else{
h = contentSize.height + ChatContentTop + ChatContentBottom;
}
_contentFrame = CGRectMake(contentX, contentY, contentSize.width + ChatContentLeft + ChatContentRight, h);
_cellHeight = MAX(CGRectGetMaxY(self.contentFrame), CGRectGetMaxY(self.iconFrame));
}
@end