YOUPAIZhaPianTextContentView2.m 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 "YOUPAIZhaPianTextContentView2.h"
  9. #import "YOUPAIZhaPianTextAttachment2.h"
  10. @interface YOUPAIZhaPianTextContentView2 ()
  11. @property(nonatomic,strong)UIView* bgView;
  12. @property(nonatomic,strong)UILabel* contentLabel;
  13. @property(nonatomic,assign)CGFloat currentY;
  14. @end
  15. @implementation YOUPAIZhaPianTextContentView2
  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:[YOUPAIZhaPianTextAttachment2 class]]) {
  40. for (UIView* subView in self.bgView.subviews) {
  41. [subView removeFromSuperview];
  42. }
  43. NSString *content = @"温馨提示:凡涉及转账均为诈骗,切勿相信,若对方要求转账请立即举报。";
  44. UILabel* contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(25.0f, 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. [self.bgView addSubview:contentLabel];
  54. self.currentY = topTitleHeight + 17.0f;
  55. }}
  56. - (void)tapHandel:(UITapGestureRecognizer*)tap{
  57. if (tap.state == UIGestureRecognizerStateEnded) {
  58. NIMKitEvent *event = [[NIMKitEvent alloc] init];
  59. event.eventName = NIMKitEventNameTapContent;
  60. event.messageModel = self.model;
  61. [self.delegate onCatchEvent:event];
  62. }
  63. }
  64. - (void)onTouchUpInside:(id)sender
  65. {
  66. NIMKitEvent *event = [[NIMKitEvent alloc] init];
  67. event.eventName = NIMKitEventNameTapContent;
  68. event.messageModel = self.model;
  69. [self.delegate onCatchEvent:event];
  70. }
  71. - (void)layoutSubviews{
  72. [super layoutSubviews];
  73. UIEdgeInsets contentInsets = self.model.contentViewInsets;
  74. CGSize contentsize = [self.model contentSize:KScreenWidth];
  75. CGRect imageViewFrame = CGRectMake(contentInsets.left, contentInsets.top, contentsize.width, contentsize.height);
  76. self.bgView.frame = imageViewFrame;
  77. }
  78. @end