NIMSessionLocationContentView.m 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // NIMSessionLocationContentView.m
  3. // NIMKit
  4. //
  5. // Created by chris on 15/2/28.
  6. // Copyright (c) 2015年 Netease. All rights reserved.
  7. //
  8. #import "NIMSessionLocationContentView.h"
  9. #import "NIMMessageModel.h"
  10. #import "UIView+NIM.h"
  11. #import "UIImage+NIMKit.h"
  12. #import "NIMKit.h"
  13. @interface NIMSessionLocationContentView()
  14. @property (nonatomic,strong) UIImageView * imageView;
  15. @property (nonatomic,strong) UILabel * titleLabel;
  16. @end
  17. @implementation NIMSessionLocationContentView
  18. - (instancetype)initSessionMessageContentView{
  19. self = [super initSessionMessageContentView];
  20. if (self) {
  21. self.opaque = YES;
  22. UIImage *image = [UIImage nim_imageInKit:@"icon_map"];
  23. _imageView = [[UIImageView alloc] initWithImage:image];
  24. CALayer *maskLayer = [CALayer layer];
  25. maskLayer.cornerRadius = 13.0;
  26. maskLayer.backgroundColor = [UIColor blackColor].CGColor;
  27. maskLayer.frame = _imageView.bounds;
  28. _imageView.layer.mask = maskLayer;
  29. [self addSubview:_imageView];
  30. _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  31. _titleLabel.textAlignment = NSTextAlignmentCenter;
  32. _titleLabel.numberOfLines = 0;
  33. [self addSubview:_titleLabel];
  34. }
  35. return self;
  36. }
  37. - (void)refresh:(NIMMessageModel *)data
  38. {
  39. [super refresh:data];
  40. NIMLocationObject * locationObject = (NIMLocationObject*)self.model.message.messageObject;
  41. self.titleLabel.text = locationObject.title;
  42. NIMKitSetting *setting = [[NIMKit sharedKit].config setting:data.message];
  43. self.titleLabel.textColor = setting.textColor;
  44. self.titleLabel.font = setting.font;
  45. }
  46. - (void)onTouchUpInside:(id)sender
  47. {
  48. NIMKitEvent *event = [[NIMKitEvent alloc] init];
  49. event.eventName = NIMKitEventNameTapContent;
  50. event.messageModel = self.model;
  51. [self.delegate onCatchEvent:event];
  52. }
  53. - (void)layoutSubviews{
  54. [super layoutSubviews];
  55. _titleLabel.nim_width = self.nim_width - 20;
  56. _titleLabel.nim_height= 35.f;
  57. self.titleLabel.nim_centerY = 90.f;
  58. self.titleLabel.nim_centerX = self.nim_width * .5f;
  59. UIEdgeInsets contentInsets = self.model.contentViewInsets;
  60. CGFloat tableViewWidth = self.superview.nim_width;
  61. CGSize contentsize = [self.model contentSize:tableViewWidth];
  62. CGRect imageViewFrame = CGRectMake(contentInsets.left, contentInsets.top, contentsize.width, contentsize.height);
  63. self.imageView.frame = imageViewFrame;
  64. }
  65. @end