| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- //
- // NTESShareAttachment.m
- // NIMDemo
- //
- // Created by Fenix Wang on 2017/8/9.
- // Copyright © 2017年 Netease. All rights reserved.
- //
- #import "NTESShareAttachment.h"
- #import "UIView+NTES.h"
- @implementation NTESShareAttachment
- - (NSString *)encodeAttachment
- {
- NSDictionary *dict = @{CMType : @(CustomMessageTypeShare),
- CMData : @{CMValue:self.info,
- CMURL:self.thumb,
- @"tradeId":self.tradeId}};
- 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 @"NTESSessionShareContentView";
- }
- - (CGSize)contentSize:(NIMMessage *)message cellWidth:(CGFloat)width{
-
- float imageWidth = 80 + 5 * 2;
- self.showTextView.width = width - 80 - imageWidth;
- [self.showTextView sizeToFit];
- CGSize size = self.showTextView.contentSize;
- size.width += imageWidth;
- size.height = MAX(size.height, imageWidth);
- return size;
- }
- - (UIEdgeInsets)contentViewInsets:(NIMMessage *)message
- {
- if (message.session.sessionType == NIMSessionTypeChatroom)
- {
- CGFloat bubbleMarginTopForImage = 15.f;
- CGFloat bubbleMarginLeftForImage = 12.f;
- return UIEdgeInsetsMake(bubbleMarginTopForImage,bubbleMarginLeftForImage,0,0);
- }
- else
- {
- CGFloat bubbleMarginForImage = 3.f;
- CGFloat bubbleArrowWidthForImage = 5.f;
- if (message.isOutgoingMsg) {
- return UIEdgeInsetsMake(bubbleMarginForImage,bubbleMarginForImage,bubbleMarginForImage,bubbleMarginForImage + bubbleArrowWidthForImage);
- }else{
- return UIEdgeInsetsMake(bubbleMarginForImage,bubbleMarginForImage + bubbleArrowWidthForImage, bubbleMarginForImage,bubbleMarginForImage);
- }
- }
- }
- - (UITextView *)showTextView
- {
- if (_showTextView == nil)
- {
- _showTextView = [[UITextView alloc] init];
- _showTextView.font = [UIFont systemFontOfSize:15];
- _showTextView.text = self.info;
- }
- return _showTextView;
- }
- @end
|