YOUPAILZGuardContentView.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // YOUPAILZGuardContentView.m
  3. // TIANYAN
  4. //
  5. // Created by CY on 2021/4/13.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZGuardContentView.h"
  9. #import "YOUPAILZGuardAttachment.h"
  10. @interface YOUPAILZGuardContentView()
  11. @property(nonatomic,strong)UIImageView* backView;
  12. @property(nonatomic,strong)UILabel* topTitle;
  13. @property(nonatomic,strong)UIImageView* iconImgView;
  14. @property(nonatomic,strong)UILabel* contentLabel;
  15. @end
  16. @implementation YOUPAILZGuardContentView
  17. - (instancetype)initSessionMessageContentView{
  18. self = [super initSessionMessageContentView];
  19. if (self) {
  20. // self.opaque = YES;
  21. UIImageView* testView = [[UIImageView alloc] initWithFrame:CGRectZero];
  22. testView.backgroundColor= [UIColor whiteColor];
  23. testView.contentMode = UIViewContentModeScaleAspectFill;
  24. testView.layer.cornerRadius = 6.0;
  25. testView.userInteractionEnabled = YES;
  26. UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHandel:)];
  27. [testView addGestureRecognizer:tap];
  28. self.backView = testView;
  29. self.bubbleImageView.hidden = YES;
  30. [self addSubview:testView];
  31. }
  32. return self;
  33. }
  34. - (void)refresh:(NIMMessageModel *)data{
  35. [super refresh:data];
  36. NIMCustomObject *customObject = (NIMCustomObject*)data.message.messageObject;
  37. id attachment = customObject.attachment;
  38. if ([attachment isKindOfClass:[YOUPAILZGuardAttachment class]]) {
  39. for (UIView* subview in self.backView.subviews) {
  40. [subview removeFromSuperview];
  41. }
  42. YOUPAILZGuardAttachment* attachment = (YOUPAILZGuardAttachment*)customObject.attachment;
  43. NSString* giftStr = @"";
  44. if (data.message.isOutgoingMsg) {
  45. giftStr = [NSString stringWithFormat:@"送%@",attachment.guard_name];
  46. }else{
  47. giftStr = [NSString stringWithFormat:@"收%@",attachment.guard_name];
  48. }
  49. UILabel* nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 0, 48)];
  50. nameLabel.textColor = [UIColor whiteColor];
  51. nameLabel.textAlignment = NSTextAlignmentLeft;
  52. nameLabel.font = LCFont(16);
  53. nameLabel.text = giftStr;
  54. CGFloat nameWidth =[giftStr widthWithFont:LCFont(16) constrainedToHeight:48];
  55. nameLabel.frame = CGRectMake(20,0,nameWidth+2, 48);
  56. [self.backView addSubview:nameLabel];
  57. UIImageView* giftImgV = [[UIImageView alloc]initWithFrame:CGRectMake(20+nameWidth+5, 0, 48, 48)];
  58. giftImgV.contentMode = UIViewContentModeScaleAspectFill;
  59. giftImgV.image = [LCTools giftImgWithGiftUrlStr:attachment.guard_url];
  60. [self.backView addSubview:giftImgV];
  61. UILabel* countLabel = [[UILabel alloc]initWithFrame:CGRectMake(20+nameWidth+60, 0, 30, 48)];
  62. countLabel.textColor = [UIColor whiteColor];
  63. countLabel.textAlignment = NSTextAlignmentLeft;
  64. countLabel.font = LCFont(17);
  65. countLabel.text = [NSString stringWithFormat:@"X%zd",attachment.guard_count];
  66. [self.backView addSubview:countLabel];
  67. CGSize contentSize = [data contentSize:KScreenWidth];
  68. UIEdgeInsets contentInsets = self.model.contentViewInsets;
  69. self.frame = CGRectMake(contentInsets.left, contentInsets.top,20+nameWidth+60+50, 48);
  70. self.backView.frame = self.frame;
  71. //设置气泡为空
  72. [self.bubbleImageView setImage:nil];
  73. [self.bubbleImageView setHighlightedImage:nil];
  74. //设置遮罩
  75. UIImageView* maskImageView = [[UIImageView alloc]init];
  76. [maskImageView setImage:[self chatBubbleImageForState:UIControlStateNormal outgoing:data.message.isOutgoingMsg]];
  77. maskImageView.frame = self.frame;
  78. self.backView.maskView = maskImageView;
  79. self.backView.image = [LCTools ColorImage:CGSizeMake(contentSize.width, contentSize.height) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight];
  80. }
  81. }
  82. - (void)tapHandel:(UITapGestureRecognizer*)tap{
  83. if (tap.state == UIGestureRecognizerStateEnded) {
  84. NIMKitEvent *event = [[NIMKitEvent alloc] init];
  85. event.eventName = NIMKitEventNameTapContent;
  86. event.messageModel = self.model;
  87. [self.delegate onCatchEvent:event];
  88. }
  89. }
  90. - (void)onTouchUpInside:(id)sender
  91. {
  92. NIMKitEvent *event = [[NIMKitEvent alloc] init];
  93. event.eventName = NIMKitEventNameTapContent;
  94. event.messageModel = self.model;
  95. [self.delegate onCatchEvent:event];
  96. }
  97. - (void)layoutSubviews{
  98. [super layoutSubviews];
  99. UIEdgeInsets contentInsets = self.model.contentViewInsets;
  100. CGSize contentSize = [self.model contentSize:KScreenWidth];
  101. CGRect imageViewFrame = CGRectMake(contentInsets.left, contentInsets.top, contentSize.width, contentSize.height);
  102. self.backView.frame = imageViewFrame;
  103. }
  104. @end