NIMSessionMessageContentView.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // NIMSessionMessageContentView.m
  3. // NIMKit
  4. //
  5. // Created by chris.
  6. // Copyright (c) 2015年 Netease. All rights reserved.
  7. //
  8. #import "NIMSessionMessageContentView.h"
  9. #import "NIMMessageModel.h"
  10. #import "UIImage+NIMKit.h"
  11. #import "UIView+NIM.h"
  12. #import "NIMKit.h"
  13. @interface NIMSessionMessageContentView()
  14. @end
  15. @implementation NIMSessionMessageContentView
  16. - (instancetype)initSessionMessageContentView
  17. {
  18. CGSize defaultBubbleSize = CGSizeMake(60, 35);
  19. if (self = [self initWithFrame:CGRectMake(0, 0, defaultBubbleSize.width, defaultBubbleSize.height)]) {
  20. [self addTarget:self action:@selector(onTouchDown:) forControlEvents:UIControlEventTouchDown];
  21. [self addTarget:self action:@selector(onTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
  22. [self addTarget:self action:@selector(onTouchUpOutside:) forControlEvents:UIControlEventTouchUpOutside];
  23. _bubbleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,defaultBubbleSize.width,defaultBubbleSize.height)];
  24. _bubbleImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  25. [self addSubview:_bubbleImageView];
  26. }
  27. return self;
  28. }
  29. - (void)refresh:(NIMMessageModel*)data
  30. {
  31. _model = data;
  32. if (!data.shouldShowLeft) {
  33. [_bubbleImageView setImage:[UIImage imageWithColor:HexColorFromRGB(0xFF6ADC)]];
  34. [_bubbleImageView setHighlightedImage:[UIImage imageWithColor:HexColorFromRGB(0xFF6ADC)]];
  35. } else {
  36. [_bubbleImageView setImage:[self chatBubbleImageForState:UIControlStateNormal outgoing:data.message.isOutgoingMsg]];
  37. [_bubbleImageView setHighlightedImage:[self chatBubbleImageForState:UIControlStateHighlighted outgoing:data.message.isOutgoingMsg]];
  38. }
  39. _bubbleImageView.layer.cornerRadius = 8;
  40. _bubbleImageView.layer.masksToBounds = YES;
  41. [self setNeedsLayout];
  42. }
  43. - (void)layoutSubviews{
  44. [super layoutSubviews];
  45. _bubbleImageView.frame = self.bounds;
  46. }
  47. - (void)updateProgress:(float)progress
  48. {
  49. }
  50. - (void)onTouchDown:(id)sender
  51. {
  52. }
  53. - (void)onTouchUpInside:(id)sender
  54. {
  55. }
  56. - (void)onTouchUpOutside:(id)sender{
  57. }
  58. #pragma mark - Private
  59. - (UIImage *)chatBubbleImageForState:(UIControlState)state outgoing:(BOOL)outgoing
  60. {
  61. NIMKitSetting *setting = [[NIMKit sharedKit].config setting:self.model.message];
  62. if (state == UIControlStateNormal)
  63. {
  64. return setting.normalBackgroundImage;
  65. }
  66. else
  67. {
  68. return setting.highLightBackgroundImage;
  69. }
  70. }
  71. - (void)setHighlighted:(BOOL)highlighted{
  72. [super setHighlighted:highlighted];
  73. _bubbleImageView.highlighted = highlighted;
  74. }
  75. @end