1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- //
- // YOUPAILCMessageTxtAttachment.m
- // LiveChat
- //
- // Created by 张灿 on 2018/9/22.
- // Copyright © 2018年 caicai. All rights reserved.
- //
- #import "YOUPAILCMessageTxtAttachment.h"
- @implementation YOUPAILCMessageTxtAttachment
- - (NSString *)encodeAttachment
- {
- NSDictionary *dict = @{
- CMType : @(CustomMessageTxt),
- CMData : @{
- CMTitle: self.title ?self.title:@"",
- CMDate: self.date ?self.date:@"",
- CMTxt1: self.txt1 ?self.txt1:@"",
- CMfields: self.fields?self.fields:@[],
- CMTxt2: self.txt2 ?self.txt2:@"",
- 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 @"YOUPAILCMessageTxtContentView";//让礼物和贴图一样的形势发送
- }
- - (CGSize)contentSize:(NIMMessageModel *)model cellWidth:(CGFloat)width{
- CGFloat topTitleHeight =[self.title heightWithFont:LCFont(14.0f) padding:3.0 constrainedToWidth:243.0f - 24.0f];
- CGFloat currentY = topTitleHeight+10.0f;
- if (![self.txt1 isEqualToString:@""]) {
- CGFloat txtOneHeight =[self.txt1 heightWithFont:LCFont(11.0f) padding:3.0 constrainedToWidth:243.0f - 24.0f];
- currentY +=txtOneHeight;
- }
- if ([self.fields isKindOfClass:[NSArray class]] && self.fields.count>0) {
- // currentY += 5.0f;
- for (NSDictionary* dict in self.fields) {
- NSString* name = [dict objectForKey:@"n"];
- NSString* value = [dict objectForKey:@"v"];
- NSString* dataStr = [NSString stringWithFormat:@"%@: %@",name,value];
- CGFloat dataLabelHeight =[dataStr heightWithFont:LCFont(11.0f) padding:3.0 constrainedToWidth:243.0f - 24.0f];
- currentY +=dataLabelHeight+5;
- }
- }
- if (![self.txt2 isEqualToString:@""]) {
- CGFloat txtTwoHeight =[self.txt2 heightWithFont:LCFont(11.0f) padding:3.0 constrainedToWidth:243.0f - 24.0f];
- currentY += txtTwoHeight + 5.0f;
- }
- currentY+=10;
- if (self.link_type!=0) {
- currentY +=32.0f;
- }
- return CGSizeMake(KScreenWidth, 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
|