YOUPAIZhaPianTextContentView.m 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // YOUPAIZhaPianTextContentView.m
  3. // YOUQU
  4. //
  5. // Created by xiaohaoran on 2021/12/13.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIZhaPianTextContentView.h"
  9. #import "YOUPAIZhaPianTextAttachment.h"
  10. @interface YOUPAIZhaPianTextContentView ()
  11. @property(nonatomic,strong)UIView* bgView;
  12. @property(nonatomic,strong)UILabel* contentLabel;
  13. @property(nonatomic,assign)CGFloat currentY;
  14. @end
  15. @implementation YOUPAIZhaPianTextContentView
  16. - (instancetype)initSessionMessageContentView{
  17. self = [super initSessionMessageContentView];
  18. if (self) {
  19. // self.opaque = YES;
  20. UIView* testView = [[UIView alloc] initWithFrame:CGRectZero];
  21. testView.backgroundColor= LCBkgColor;
  22. UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHandel:)];
  23. [testView addGestureRecognizer:tap];
  24. self.bgView = testView;
  25. self.bubbleImageView.hidden = YES;
  26. [self addSubview:testView];
  27. UILabel* contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(14.0f, 0, KScreenWidth-28.0f, 20)];
  28. self.contentLabel = contentLabel;
  29. contentLabel.font = [UIFont systemFontOfSize:18];
  30. contentLabel.textColor = LCTextBlack;
  31. [self.bgView addSubview:contentLabel];
  32. }
  33. return self;
  34. }
  35. - (void)refresh:(NIMMessageModel *)data{
  36. [super refresh:data];
  37. NIMCustomObject *customObject = (NIMCustomObject*)data.message.messageObject;
  38. id attachment = customObject.attachment;
  39. if ([attachment isKindOfClass:[YOUPAIZhaPianTextAttachment class]]) {
  40. for (UIView* subView in self.bgView.subviews) {
  41. [subView removeFromSuperview];
  42. }
  43. NSString *content = @"贸然留外部联系方式可能有安全风险. 恶意留外部联系方式、引流,账号将会封禁, 请勿转账、谨防诈骗。";
  44. UILabel* contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(25, 0.0f, KScreenWidth-50.0f, 50.0f)];
  45. contentLabel.numberOfLines = 0;
  46. self.contentLabel = contentLabel;
  47. CGFloat topTitleHeight = [content heightWithFont:[UIFont systemFontOfSize:12] padding:3.0 constrainedToWidth:KScreenWidth-50.0f];
  48. contentLabel.text = content;
  49. contentLabel.font = [UIFont systemFontOfSize:12];
  50. contentLabel.textColor = [UIColor grayColor];
  51. contentLabel.textAlignment = NSTextAlignmentCenter;
  52. contentLabel.mj_h = topTitleHeight+2;
  53. // [UILabel changeLineSpaceForLabel:contentLabel WithSpace:3.0];
  54. [self.bgView addSubview:contentLabel];
  55. self.currentY = topTitleHeight + 17.0f;
  56. }}
  57. - (void)tapHandel:(UITapGestureRecognizer*)tap{
  58. if (tap.state == UIGestureRecognizerStateEnded) {
  59. NIMKitEvent *event = [[NIMKitEvent alloc] init];
  60. event.eventName = NIMKitEventNameTapContent;
  61. event.messageModel = self.model;
  62. [self.delegate onCatchEvent:event];
  63. }
  64. }
  65. - (void)onTouchUpInside:(id)sender
  66. {
  67. NIMKitEvent *event = [[NIMKitEvent alloc] init];
  68. event.eventName = NIMKitEventNameTapContent;
  69. event.messageModel = self.model;
  70. [self.delegate onCatchEvent:event];
  71. }
  72. - (void)layoutSubviews{
  73. [super layoutSubviews];
  74. UIEdgeInsets contentInsets = self.model.contentViewInsets;
  75. CGSize contentsize = [self.model contentSize:KScreenWidth];
  76. CGRect imageViewFrame = CGRectMake(contentInsets.left, contentInsets.top, contentsize.width, contentsize.height);
  77. self.bgView.frame = imageViewFrame;
  78. }
  79. @end