2
0

WFCULocationCell.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // ImageCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/9/2.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCULocationCell.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. @interface WFCULocationCell ()
  11. @property(nonatomic, strong) UIImageView *shadowMaskView;
  12. @property (nonatomic, strong)UIImageView *thumbnailView;
  13. @property (nonatomic, strong)UILabel *titleLabel;
  14. @end
  15. @implementation WFCULocationCell
  16. + (CGSize)sizeForClientArea:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
  17. WFCCLocationMessageContent *imgContent = (WFCCLocationMessageContent *)msgModel.message.content;
  18. CGSize size = imgContent.thumbnail.size;
  19. if (size.height > width || size.width > width) {
  20. float scale = MIN(width/size.height, width/size.width);
  21. size = CGSizeMake(size.width * scale, size.height * scale);
  22. }
  23. return size;
  24. }
  25. - (void)setModel:(WFCUMessageModel *)model {
  26. [super setModel:model];
  27. WFCCLocationMessageContent *imgContent = (WFCCLocationMessageContent *)model.message.content;
  28. self.thumbnailView.frame = self.bubbleView.bounds;
  29. self.thumbnailView.image = imgContent.thumbnail;
  30. self.titleLabel.text = imgContent.title;
  31. }
  32. - (UIImageView *)thumbnailView {
  33. if (!_thumbnailView) {
  34. _thumbnailView = [[UIImageView alloc] init];
  35. [self.bubbleView addSubview:_thumbnailView];
  36. }
  37. return _thumbnailView;
  38. }
  39. - (UILabel *)titleLabel {
  40. if (!_titleLabel) {
  41. _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.bubbleView.frame.size.width, 20)];
  42. _titleLabel.font = [UIFont systemFontOfSize:12];
  43. _titleLabel.textAlignment = NSTextAlignmentCenter;
  44. _titleLabel.backgroundColor = [UIColor colorWithRed:0.7f green:0.7f blue:0.7f alpha:0.5f];
  45. [self.bubbleView addSubview:_titleLabel];
  46. }
  47. return _titleLabel;
  48. }
  49. - (void)setMaskImage:(UIImage *)maskImage{
  50. [super setMaskImage:maskImage];
  51. if (_shadowMaskView) {
  52. [_shadowMaskView removeFromSuperview];
  53. }
  54. _shadowMaskView = [[UIImageView alloc] initWithImage:maskImage];
  55. CGRect frame = CGRectMake(self.bubbleView.frame.origin.x - 1, self.bubbleView.frame.origin.y - 1, self.bubbleView.frame.size.width + 2, self.bubbleView.frame.size.height + 2);
  56. _shadowMaskView.frame = frame;
  57. [self.contentView addSubview:_shadowMaskView];
  58. [self.contentView bringSubviewToFront:self.bubbleView];
  59. }
  60. @end