NIMTextContentConfig.m 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // NIMTextContentConfig.m
  3. // NIMKit
  4. //
  5. // Created by amao on 9/15/15.
  6. // Copyright (c) 2015 NetEase. All rights reserved.
  7. //
  8. #import "NIMTextContentConfig.h"
  9. #import "M80AttributedLabel+NIMKit.h"
  10. #import "NIMKit.h"
  11. @interface NIMTextContentConfig()
  12. @property (nonatomic,strong) M80AttributedLabel *label;
  13. @end
  14. @implementation NIMTextContentConfig
  15. - (CGSize)contentSize:(CGFloat)cellWidth message:(NIMMessage *)message
  16. {
  17. NSString *text = message.text;
  18. self.label.font = [[NIMKit sharedKit].config setting:message].font;
  19. [self.label nim_setText:text];
  20. CGFloat msgBubbleMaxWidth = (cellWidth - 130);
  21. CGFloat bubbleLeftToContent = 14;
  22. CGFloat contentRightToBubble = 14;
  23. CGFloat msgContentMaxWidth = (msgBubbleMaxWidth - contentRightToBubble - bubbleLeftToContent);
  24. return [self.label sizeThatFits:CGSizeMake(msgContentMaxWidth, CGFLOAT_MAX)];
  25. }
  26. - (NSString *)cellContent:(NIMMessage *)message
  27. {
  28. return @"NIMSessionTextContentView";
  29. }
  30. - (UIEdgeInsets)contentViewInsets:(NIMMessage *)message
  31. {
  32. return [[NIMKit sharedKit].config setting:message].contentInsets;
  33. }
  34. #pragma mark - Private
  35. - (M80AttributedLabel *)label
  36. {
  37. if (_label) {
  38. return _label;
  39. }
  40. _label = [[M80AttributedLabel alloc] initWithFrame:CGRectZero];
  41. return _label;
  42. }
  43. @end