NTESSessionTipContentView.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // NTESSessionTipContentView.m
  3. // NIM
  4. //
  5. // Created by chris on 2016/11/6.
  6. // Copyright © 2016年 Netease. All rights reserved.
  7. //
  8. #import "NTESSessionTipContentView.h"
  9. #import "NTESCustomAttachmentDefines.h"
  10. #import "UIView+NTES.h"
  11. @implementation NTESSessionTipContentView
  12. - (instancetype)initSessionMessageContentView
  13. {
  14. if (self = [super initSessionMessageContentView]) {
  15. _label = [[UILabel alloc] initWithFrame:CGRectZero];
  16. _label.numberOfLines = 0;
  17. [self addSubview:_label];
  18. }
  19. return self;
  20. }
  21. - (void)refresh:(NIMMessageModel *)model{
  22. [super refresh:model];
  23. NIMCustomObject *object = (NIMCustomObject *)model.message.messageObject;
  24. id<NTESCustomAttachmentInfo> attachment = (id<NTESCustomAttachmentInfo>)object.attachment;
  25. if ([attachment respondsToSelector:@selector(formatedMessage)]) {
  26. self.label.text = [attachment formatedMessage];
  27. }
  28. self.label.textColor = [UIColor whiteColor];;
  29. self.label.font = [UIFont systemFontOfSize:10.f];
  30. }
  31. - (UIImage *)chatBubbleImageForState:(UIControlState)state outgoing:(BOOL)outgoing
  32. {
  33. NSString *name = [[[NIMKit sharedKit] resourceBundleName] stringByAppendingPathComponent:@"icon_session_time_bg"];
  34. UIEdgeInsets insets = UIEdgeInsetsFromString(@"{8,20,8,20}");
  35. return [[UIImage imageNamed:name] resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
  36. }
  37. - (void)layoutSubviews
  38. {
  39. [super layoutSubviews];
  40. CGFloat padding = 20.f;
  41. self.label.size = [self.label sizeThatFits:CGSizeMake(self.width - 2 * padding, CGFLOAT_MAX)];
  42. self.label.centerX = self.width * .5f;
  43. self.label.centerY = self.height * .5f;
  44. self.bubbleImageView.frame = CGRectInset(self.label.frame, -8, -4);
  45. }
  46. @end