JXRedPacketCell.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //
  2. // JXRedPacketCell.m
  3. // shiku_im
  4. //
  5. // Created by Apple on 16/10/10.
  6. // Copyright © 2016年 Reese. All rights reserved.
  7. //
  8. #import "JXRedPacketCell.h"
  9. @interface JXRedPacketCell ()
  10. @property (nonatomic, strong) UIImageView *headImageView;
  11. @property (nonatomic, strong) UILabel *nameLabel;
  12. @property (nonatomic, strong) UILabel *title;
  13. @end
  14. @implementation JXRedPacketCell
  15. - (void)awakeFromNib {
  16. [super awakeFromNib];
  17. // Initialization code
  18. }
  19. -(void)creatUI{
  20. self.bubbleBg.custom_acceptEventInterval = 1.0;
  21. _imageBackground =[[JXImageView alloc]initWithFrame:CGRectZero];
  22. [_imageBackground setBackgroundColor:[UIColor clearColor]];
  23. _imageBackground.layer.cornerRadius = 6;
  24. _imageBackground.image = [UIImage imageNamed:@"hongbaokuan"];
  25. _imageBackground.contentMode = UIViewContentModeScaleAspectFill;
  26. _imageBackground.layer.masksToBounds = YES;
  27. [self.bubbleBg addSubview:_imageBackground];
  28. _headImageView = [[UIImageView alloc]init];
  29. _headImageView.frame = CGRectMake(15,10, 32, 42);
  30. _headImageView.image = [UIImage imageNamed:@"hongb"];
  31. _headImageView.userInteractionEnabled = NO;
  32. [_imageBackground addSubview:_headImageView];
  33. _nameLabel = [[UILabel alloc]init];
  34. _nameLabel.frame = CGRectMake(CGRectGetMaxX(_headImageView.frame) + 15,10, 180, 20);
  35. _nameLabel.font = g_factory.font15;
  36. _nameLabel.textColor = [UIColor whiteColor];
  37. _nameLabel.numberOfLines = 0;
  38. _nameLabel.userInteractionEnabled = NO;
  39. [_imageBackground addSubview:_nameLabel];
  40. _title = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxY(_headImageView.frame) + 15, CGRectGetMaxX(_nameLabel.frame)+5, 100, 14)];
  41. _title.text = Localized(@"JX_BusinessCard");
  42. _title.font = SYSFONT(14.0);
  43. _title.textColor = [UIColor whiteColor];
  44. [_imageBackground addSubview:_title];
  45. //
  46. // _redPacketGreet = [[JXEmoji alloc]initWithFrame:CGRectMake(5, 25, 80, 16)];
  47. // _redPacketGreet.textAlignment = NSTextAlignmentCenter;
  48. // _redPacketGreet.font = [UIFont systemFontOfSize:12];
  49. // _redPacketGreet.textColor = [UIColor whiteColor];
  50. // _redPacketGreet.userInteractionEnabled = NO;
  51. // [_imageBackground addSubview:_redPacketGreet];
  52. }
  53. -(void)setCellData{
  54. [super setCellData];
  55. int n = imageItemHeight;
  56. if(self.msg.isMySend)
  57. {
  58. self.bubbleBg.frame=CGRectMake(CGRectGetMinX(self.headImage.frame)- kChatCellMaxWidth - CHAT_WIDTH_ICON, INSETS+10, kChatCellMaxWidth, n+INSETS -4);
  59. _imageBackground.frame = self.bubbleBg.bounds;
  60. }
  61. else
  62. {
  63. self.bubbleBg.frame=CGRectMake(CGRectGetMaxX(self.headImage.frame) + CHAT_WIDTH_ICON, INSETS2(self.msg.isGroup)+10, kChatCellMaxWidth, n+INSETS -4);
  64. _imageBackground.frame = self.bubbleBg.bounds;
  65. }
  66. _title.frame = CGRectMake(CGRectGetMaxX(_headImageView.frame) + 15, CGRectGetMaxY(_nameLabel.frame)+2.5, 100, 14);
  67. if (self.msg.isShowTime) {
  68. CGRect frame = self.bubbleBg.frame;
  69. frame.origin.y = self.bubbleBg.frame.origin.y + 40;
  70. self.bubbleBg.frame = frame;
  71. }
  72. [self setMaskLayer:_imageBackground];
  73. //服务端返回的数据类型错乱,强行改
  74. self.msg.fileName = [NSString stringWithFormat:@"%@",self.msg.fileName];
  75. if ([self.msg.fileName isEqualToString:@"3"]) {
  76. // _imageBackground.image = [UIImage imageNamed:@"口令红包"];
  77. // _redPacketGreet.frame = CGRectMake(5, 45, _imageBackground.frame.size.width -10, 16);
  78. _nameLabel.text = self.msg.content;
  79. _title.text = Localized(@"JX_MesGift");
  80. }else{
  81. // _imageBackground.image = [UIImage imageNamed:@"红包"];
  82. // _redPacketGreet.frame = CGRectMake(5, 25, _imageBackground.frame.size.width -10, 16);
  83. _nameLabel.text = self.msg.content;
  84. _title.text = Localized(@"JXredPacket");
  85. }
  86. if ([self.msg.fileSize intValue] == 2) {
  87. _imageBackground.alpha = 0.5;
  88. }else {
  89. _imageBackground.alpha = 1;
  90. }
  91. }
  92. -(void)didTouch:(UIButton*)button{
  93. if ([self.msg.fileName isEqualToString:@"3"]) {
  94. // //如果可以打开
  95. // if([self.msg.fileSize intValue] != 2){
  96. // [g_App showAlert:Localized(@"JX_WantOpenGift")];
  97. // return;
  98. // }
  99. [g_notify postNotificationName:kcellRedPacketDidTouchNotifaction object:self.msg];
  100. }
  101. if ([self.msg.fileName isEqualToString:@"1"] || [self.msg.fileName isEqualToString:@"2"]) {
  102. //如果可以打开
  103. // if([self.msg.fileSize intValue] != 2){
  104. [g_notify postNotificationName:kcellRedPacketDidTouchNotifaction object:self.msg];
  105. return;
  106. // }
  107. }
  108. // [g_server getRedPacket:self.msg.objectId toView:self.chatView];
  109. }
  110. + (float)getChatCellHeight:(JXMessageObject *)msg {
  111. if ([g_App.isShowRedPacket intValue] == 1){
  112. if ([msg.chatMsgHeight floatValue] > 1) {
  113. return [msg.chatMsgHeight floatValue];
  114. }
  115. float n = 0;
  116. if (msg.isGroup && !msg.isMySend) {
  117. if (msg.isShowTime) {
  118. n = JX_SCREEN_WIDTH/3 + 10 + 40;
  119. }else {
  120. n = JX_SCREEN_WIDTH/3 + 10;
  121. }
  122. n += GROUP_CHAT_INSET;
  123. }else {
  124. if (msg.isShowTime) {
  125. n = JX_SCREEN_WIDTH/3 + 40;
  126. }else {
  127. n = JX_SCREEN_WIDTH/3;
  128. }
  129. }
  130. msg.chatMsgHeight = [NSString stringWithFormat:@"%f",n];
  131. if (!msg.isNotUpdateHeight) {
  132. [msg updateChatMsgHeight];
  133. }
  134. return n+10;
  135. }else{
  136. msg.chatMsgHeight = [NSString stringWithFormat:@"0"];
  137. if (!msg.isNotUpdateHeight) {
  138. [msg updateChatMsgHeight];
  139. }
  140. return 0+10;
  141. }
  142. }
  143. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  144. [super setSelected:selected animated:animated];
  145. // Configure the view for the selected state
  146. }
  147. @end