YOUPAILCOneImageAttachment.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // YOUPAILCOneImageAttachment.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/9/22.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCOneImageAttachment.h"
  9. @implementation YOUPAILCOneImageAttachment
  10. - (NSString *)encodeAttachment
  11. {
  12. NSDictionary *dict = @{
  13. CMType : @(CustomOneImage),
  14. CMData : @{
  15. CMAct_Type: self.act_type ?[NSNumber numberWithInteger:self.act_type]:@0,
  16. CMAct_String: self.act_string ?self.act_string:@"",
  17. CMImage: self.image ?self.image:@"",
  18. CMTitle: self.title ?self.title:@"",
  19. CMTxt: self.txt ?self.txt:@"",
  20. CMLink_url: self.link_url ?self.link_url:@"",
  21. CMLink_type: self.link_type ?[NSNumber numberWithInteger:self.link_type]:@0,
  22. }
  23. };
  24. NSData *data = [NSJSONSerialization dataWithJSONObject:dict
  25. options:0
  26. error:nil];
  27. NSString *content = nil;
  28. if (data) {
  29. content = [[NSString alloc] initWithData:data
  30. encoding:NSUTF8StringEncoding];
  31. }
  32. return content;
  33. }
  34. - (NSString *)cellContent:(NIMMessage *)message{
  35. return @"YOUPAILCOneImageContentView";//
  36. }
  37. - (CGSize)contentSize:(NIMMessageModel *)model cellWidth:(CGFloat)width{
  38. CGFloat currentY = (KScreenWidth-30)*9/16;
  39. if (self.act_type==2) {
  40. if (![self.title isEqualToString:@""]) {
  41. CGFloat txtOneHeight =[self.title heightWithFont:[UIFont boldSystemFontOfSize:16] padding:3.0 constrainedToWidth:KScreenWidth-70];
  42. currentY +=txtOneHeight+22;
  43. }
  44. if (![self.txt isEqualToString:@""]) {
  45. CGFloat txtTwoHeight =[self.txt heightWithFont:[UIFont systemFontOfSize:15] padding:3.0 constrainedToWidth:KScreenWidth-70];
  46. currentY +=txtTwoHeight+12;
  47. }
  48. currentY +=20;
  49. }
  50. return CGSizeMake(KScreenWidth-30, currentY);
  51. }
  52. - (UIEdgeInsets)contentViewInsets:(NIMMessage *)message
  53. {
  54. return UIEdgeInsetsZero;
  55. // CGFloat bubblePaddingForImage = 3.f;
  56. // CGFloat bubbleArrowWidthForImage = 5.f;
  57. // if (message.isOutgoingMsg) {
  58. // return UIEdgeInsetsMake(bubblePaddingForImage,bubblePaddingForImage,bubblePaddingForImage,bubblePaddingForImage + bubbleArrowWidthForImage);
  59. // }else{
  60. // return UIEdgeInsetsMake(bubblePaddingForImage,bubblePaddingForImage + bubbleArrowWidthForImage, bubblePaddingForImage,bubblePaddingForImage);
  61. // }
  62. }
  63. @end