// // YOUPAIZhaPianTextContentView.m // YOUQU // // Created by xiaohaoran on 2021/12/13. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAIZhaPianTextContentView2.h" #import "YOUPAIZhaPianTextAttachment2.h" @interface YOUPAIZhaPianTextContentView2 () @property(nonatomic,strong)UIView* bgView; @property(nonatomic,strong)UILabel* contentLabel; @property(nonatomic,assign)CGFloat currentY; @end @implementation YOUPAIZhaPianTextContentView2 - (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:[YOUPAIZhaPianTextAttachment2 class]]) { for (UIView* subView in self.bgView.subviews) { [subView removeFromSuperview]; } NSString *content = @"温馨提示:凡涉及转账均为诈骗,切勿相信,若对方要求转账请立即举报。"; UILabel* contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(25.0f, 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; [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