123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //
- // YOUPAILZGuardContentView.m
- // TIANYAN
- //
- // Created by CY on 2021/4/13.
- // Copyright © 2021 leo. All rights reserved.
- //
- #import "YOUPAILZGuardContentView.h"
- #import "YOUPAILZGuardAttachment.h"
- @interface YOUPAILZGuardContentView()
- @property(nonatomic,strong)UIImageView* backView;
- @property(nonatomic,strong)UILabel* topTitle;
- @property(nonatomic,strong)UIImageView* iconImgView;
- @property(nonatomic,strong)UILabel* contentLabel;
- @end
- @implementation YOUPAILZGuardContentView
- - (instancetype)initSessionMessageContentView{
- self = [super initSessionMessageContentView];
- if (self) {
- // self.opaque = YES;
- UIImageView* testView = [[UIImageView alloc] initWithFrame:CGRectZero];
- testView.backgroundColor= [UIColor whiteColor];
- testView.contentMode = UIViewContentModeScaleAspectFill;
- testView.layer.cornerRadius = 6.0;
- testView.userInteractionEnabled = YES;
- UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHandel:)];
- [testView addGestureRecognizer:tap];
- self.backView = testView;
- self.bubbleImageView.hidden = YES;
- [self addSubview:testView];
- }
- return self;
- }
- - (void)refresh:(NIMMessageModel *)data{
- [super refresh:data];
- NIMCustomObject *customObject = (NIMCustomObject*)data.message.messageObject;
- id attachment = customObject.attachment;
- if ([attachment isKindOfClass:[YOUPAILZGuardAttachment class]]) {
- for (UIView* subview in self.backView.subviews) {
- [subview removeFromSuperview];
- }
- YOUPAILZGuardAttachment* attachment = (YOUPAILZGuardAttachment*)customObject.attachment;
- NSString* giftStr = @"";
- if (data.message.isOutgoingMsg) {
- giftStr = [NSString stringWithFormat:@"送%@",attachment.guard_name];
- }else{
- giftStr = [NSString stringWithFormat:@"收%@",attachment.guard_name];
- }
- UILabel* nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 0, 48)];
- nameLabel.textColor = [UIColor whiteColor];
- nameLabel.textAlignment = NSTextAlignmentLeft;
- nameLabel.font = LCFont(16);
- nameLabel.text = giftStr;
- CGFloat nameWidth =[giftStr widthWithFont:LCFont(16) constrainedToHeight:48];
- nameLabel.frame = CGRectMake(20,0,nameWidth+2, 48);
- [self.backView addSubview:nameLabel];
-
- UIImageView* giftImgV = [[UIImageView alloc]initWithFrame:CGRectMake(20+nameWidth+5, 0, 48, 48)];
- giftImgV.contentMode = UIViewContentModeScaleAspectFill;
- giftImgV.image = [LCTools giftImgWithGiftUrlStr:attachment.guard_url];
- [self.backView addSubview:giftImgV];
-
- UILabel* countLabel = [[UILabel alloc]initWithFrame:CGRectMake(20+nameWidth+60, 0, 30, 48)];
- countLabel.textColor = [UIColor whiteColor];
- countLabel.textAlignment = NSTextAlignmentLeft;
- countLabel.font = LCFont(17);
- countLabel.text = [NSString stringWithFormat:@"X%zd",attachment.guard_count];
- [self.backView addSubview:countLabel];
-
- CGSize contentSize = [data contentSize:KScreenWidth];
- UIEdgeInsets contentInsets = self.model.contentViewInsets;
- self.frame = CGRectMake(contentInsets.left, contentInsets.top,20+nameWidth+60+50, 48);
- self.backView.frame = self.frame;
- //设置气泡为空
- [self.bubbleImageView setImage:nil];
- [self.bubbleImageView setHighlightedImage:nil];
- //设置遮罩
- UIImageView* maskImageView = [[UIImageView alloc]init];
- [maskImageView setImage:[self chatBubbleImageForState:UIControlStateNormal outgoing:data.message.isOutgoingMsg]];
- maskImageView.frame = self.frame;
- self.backView.maskView = maskImageView;
- self.backView.image = [LCTools ColorImage:CGSizeMake(contentSize.width, contentSize.height) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight];
- }
-
- }
- - (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.backView.frame = imageViewFrame;
-
- }
- @end
|