NTESSessionJankenponContentView.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // NTESSessionCustomContentView.m
  3. // NIM
  4. //
  5. // Created by chris on 15/4/10.
  6. // Copyright (c) 2015年 Netease. All rights reserved.
  7. //
  8. #import "NTESSessionJankenponContentView.h"
  9. #import "UIView+NTES.h"
  10. #import "NTESJanKenPonAttachment.h"
  11. #import "NTESSessionUtil.h"
  12. @interface NTESSessionJankenponContentView()
  13. @property (nonatomic,strong,readwrite) UIImageView *imageView;
  14. @end
  15. @implementation NTESSessionJankenponContentView
  16. - (instancetype)initSessionMessageContentView{
  17. self = [super initSessionMessageContentView];
  18. if (self) {
  19. self.opaque = YES;
  20. _imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
  21. [self addSubview:_imageView];
  22. }
  23. return self;
  24. }
  25. - (void)refresh:(NIMMessageModel *)data
  26. {
  27. [super refresh:data];
  28. NIMCustomObject *customObject = (NIMCustomObject*)data.message.messageObject;
  29. id attachment = customObject.attachment;
  30. if ([attachment isKindOfClass:[NTESJanKenPonAttachment class]]) {
  31. self.imageView.image = [attachment showCoverImage];
  32. [self.imageView sizeToFit];
  33. }
  34. }
  35. - (void)layoutSubviews{
  36. [super layoutSubviews];
  37. UIEdgeInsets contentInsets = self.model.contentViewInsets;
  38. CGFloat tableViewWidth = self.superview.width;
  39. CGSize contentSize = [self.model contentSize:tableViewWidth];
  40. CGRect imageViewFrame = CGRectMake(contentInsets.left, contentInsets.top, contentSize.width, contentSize.height);
  41. self.imageView.frame = imageViewFrame;
  42. CALayer *maskLayer = [CALayer layer];
  43. maskLayer.cornerRadius = 13.0;
  44. maskLayer.backgroundColor = [UIColor blackColor].CGColor;
  45. maskLayer.frame = self.imageView.bounds;
  46. self.imageView.layer.mask = maskLayer;
  47. }
  48. - (UIImage *)chatBubbleImageForState:(UIControlState)state outgoing:(BOOL)outgoing{
  49. if (self.model.message.session.sessionType == NIMSessionTypeChatroom) {
  50. return nil;
  51. }
  52. return [super chatBubbleImageForState:state outgoing:outgoing];
  53. }
  54. @end