// // YOUPAILCOneImageAttachment.m // LiveChat // // Created by 张灿 on 2018/9/22. // Copyright © 2018年 caicai. All rights reserved. // #import "YOUPAILCOneImageAttachment.h" @implementation YOUPAILCOneImageAttachment - (NSString *)encodeAttachment { NSDictionary *dict = @{ CMType : @(CustomOneImage), CMData : @{ CMAct_Type: self.act_type ?[NSNumber numberWithInteger:self.act_type]:@0, CMAct_String: self.act_string ?self.act_string:@"", CMImage: self.image ?self.image:@"", CMTitle: self.title ?self.title:@"", CMTxt: self.txt ?self.txt:@"", CMLink_url: self.link_url ?self.link_url:@"", CMLink_type: self.link_type ?[NSNumber numberWithInteger:self.link_type]:@0, } }; NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:0 error:nil]; NSString *content = nil; if (data) { content = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; } return content; } - (NSString *)cellContent:(NIMMessage *)message{ return @"YOUPAILCOneImageContentView";// } - (CGSize)contentSize:(NIMMessageModel *)model cellWidth:(CGFloat)width{ CGFloat currentY = (KScreenWidth-30)*9/16; if (self.act_type==2) { if (![self.title isEqualToString:@""]) { CGFloat txtOneHeight =[self.title heightWithFont:[UIFont boldSystemFontOfSize:16] padding:3.0 constrainedToWidth:KScreenWidth-70]; currentY +=txtOneHeight+22; } if (![self.txt isEqualToString:@""]) { CGFloat txtTwoHeight =[self.txt heightWithFont:[UIFont systemFontOfSize:15] padding:3.0 constrainedToWidth:KScreenWidth-70]; currentY +=txtTwoHeight+12; } currentY +=20; } return CGSizeMake(KScreenWidth-30, currentY); } - (UIEdgeInsets)contentViewInsets:(NIMMessage *)message { return UIEdgeInsetsZero; // CGFloat bubblePaddingForImage = 3.f; // CGFloat bubbleArrowWidthForImage = 5.f; // if (message.isOutgoingMsg) { // return UIEdgeInsetsMake(bubblePaddingForImage,bubblePaddingForImage,bubblePaddingForImage,bubblePaddingForImage + bubbleArrowWidthForImage); // }else{ // return UIEdgeInsetsMake(bubblePaddingForImage,bubblePaddingForImage + bubbleArrowWidthForImage, bubblePaddingForImage,bubblePaddingForImage); // } } @end