CNLiveMessageFrame.m 1.86 KB
//
//  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