// // YOUPAIZhaPianTextContentView.m // YOUQU // // Created by xiaohaoran on 2021/12/13. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAIZhaPianTextContentView.h" #import "YOUPAIZhaPianTextAttachment.h" @interface YOUPAIZhaPianTextContentView () @property(nonatomic,strong)UIView* bgView; @property(nonatomic,strong)UILabel* contentLabel; @property(nonatomic,assign)CGFloat currentY; @end @implementation YOUPAIZhaPianTextContentView - (instancetype)initSessionMessageContentView{ self = [super initSessionMessageContentView]; if (self) { // self.opaque = YES; UIView* testView = [[UIView alloc] initWithFrame:CGRectZero]; testView.backgroundColor= LCBkgColor; UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHandel:)]; [testView addGestureRecognizer:tap]; self.bgView = testView; self.bubbleImageView.hidden = YES; [self addSubview:testView]; UILabel* contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(14.0f, 0, KScreenWidth-28.0f, 20)]; self.contentLabel = contentLabel; contentLabel.font = [UIFont systemFontOfSize:18]; contentLabel.textColor = LCTextBlack; [self.bgView addSubview:contentLabel]; } return self; } - (void)refresh:(NIMMessageModel *)data{ [super refresh:data]; NIMCustomObject *customObject = (NIMCustomObject*)data.message.messageObject; id attachment = customObject.attachment; if ([attachment isKindOfClass:[YOUPAIZhaPianTextAttachment class]]) { for (UIView* subView in self.bgView.subviews) { [subView removeFromSuperview]; } NSString *content = @"贸然留外部联系方式可能有安全风险. 恶意留外部联系方式、引流,账号将会封禁, 请勿转账、谨防诈骗。"; UILabel* contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(25, 0.0f, KScreenWidth-50.0f, 50.0f)]; contentLabel.numberOfLines = 0; self.contentLabel = contentLabel; CGFloat topTitleHeight = [content heightWithFont:[UIFont systemFontOfSize:12] padding:3.0 constrainedToWidth:KScreenWidth-50.0f]; contentLabel.text = content; contentLabel.font = [UIFont systemFontOfSize:12]; contentLabel.textColor = [UIColor grayColor]; contentLabel.textAlignment = NSTextAlignmentCenter; contentLabel.mj_h = topTitleHeight+2; // [UILabel changeLineSpaceForLabel:contentLabel WithSpace:3.0]; [self.bgView addSubview:contentLabel]; self.currentY = topTitleHeight + 17.0f; }} - (void)tapHandel:(UITapGestureRecognizer*)tap{ if (tap.state == UIGestureRecognizerStateEnded) { NIMKitEvent *event = [[NIMKitEvent alloc] init]; event.eventName = NIMKitEventNameTapContent; event.messageModel = self.model; [self.delegate onCatchEvent:event]; } } - (void)onTouchUpInside:(id)sender { NIMKitEvent *event = [[NIMKitEvent alloc] init]; event.eventName = NIMKitEventNameTapContent; event.messageModel = self.model; [self.delegate onCatchEvent:event]; } - (void)layoutSubviews{ [super layoutSubviews]; UIEdgeInsets contentInsets = self.model.contentViewInsets; CGSize contentsize = [self.model contentSize:KScreenWidth]; CGRect imageViewFrame = CGRectMake(contentInsets.left, contentInsets.top, contentsize.width, contentsize.height); self.bgView.frame = imageViewFrame; } @end