YBLiveChatCell.m 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // YBLiveChatCell.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2019/12/3.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "YBLiveChatCell.h"
  9. #import "SDWebImageManager.h"
  10. @implementation YBLiveChatCell
  11. - (void)awakeFromNib {
  12. [super awakeFromNib];
  13. self.contentView.backgroundColor = UIColor.clearColor;
  14. self.backgroundColor = UIColor.clearColor;
  15. }
  16. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  17. [super setSelected:selected animated:animated];
  18. }
  19. - (void)setModel:(YBLiveChatModel *)model {
  20. _model = model;
  21. _model = model;
  22. if ([_model.titleColor isEqual:@"userLogin"]) {
  23. _chatLabel.text = [NSString stringWithFormat:@"%@ %@",_model.userName,_model.contentChat];
  24. }else if ([_model.titleColor isEqual:@"redbag"]){
  25. _chatLabel.text = [NSString stringWithFormat:@"%@%@",_model.userName,_model.contentChat];
  26. }else{
  27. _chatLabel.text = [NSString stringWithFormat:@"%@:%@",_model.userName,_model.contentChat];
  28. }
  29. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:self.chatLabel.text attributes:nil];
  30. _chatLabel.font = [UIFont systemFontOfSize:14];
  31. //入场消息 开播警告
  32. if ([_model.titleColor isEqual:@"firstlogin"]) {
  33. self.chatView.backgroundColor = RGB_COLOR(@"#000000", 0.3);
  34. _chatLabel.textColor = Pink_Cor;
  35. noteStr = [[NSMutableAttributedString alloc] initWithString:_model.contentChat attributes:nil];
  36. }else if ([_model.titleColor isEqual:@"redbag"]){
  37. _chatLabel.textColor = [UIColor whiteColor];
  38. _chatLabel.font = [UIFont boldSystemFontOfSize:14];
  39. self.chatView.backgroundColor = RGB_COLOR(@"#f7501d", 0.9);
  40. }
  41. else{
  42. self.chatView.backgroundColor = RGB_COLOR(@"#000000", 0.3);
  43. NSAttributedString *speaceString = [[NSAttributedString alloc]initWithString:@" "];
  44. //超管
  45. NSTextAttachment *adminAttchment = [[NSTextAttachment alloc]init];
  46. adminAttchment.bounds = CGRectMake(0, -2, 20, 15);//设置frame
  47. adminAttchment.image = [UIImage imageNamed:getImagename(@"chat_admin")];//设置图片
  48. NSAttributedString *adminString = [NSAttributedString attributedStringWithAttachment:(NSTextAttachment *)(adminAttchment)];
  49. //vip
  50. NSTextAttachment *vipAttchment = [[NSTextAttachment alloc]init];
  51. vipAttchment.bounds = CGRectMake(0, -2, 30, 15);//设置frame
  52. vipAttchment.image = [UIImage imageNamed:@"chat_vip"];//设置图片
  53. NSAttributedString *vipString = [NSAttributedString attributedStringWithAttachment:(NSTextAttachment *)(vipAttchment)];
  54. //守护
  55. NSTextAttachment *shouAttchment = [[NSTextAttachment alloc]init];
  56. shouAttchment.bounds = CGRectMake(0, -2, 15, 15);//设置frame
  57. shouAttchment.image = [UIImage imageNamed:getImagename(@"chat_shou_month")];//设置图片
  58. NSAttributedString *shouString = [NSAttributedString attributedStringWithAttachment:(NSTextAttachment *)(shouAttchment)];
  59. NSTextAttachment *yearAttchment = [[NSTextAttachment alloc]init];
  60. yearAttchment.bounds = CGRectMake(0, -2, 15, 15);//设置frame
  61. yearAttchment.image = [UIImage imageNamed:getImagename(@"chat_shou_year")];//设置图片
  62. NSAttributedString *yearString = [NSAttributedString attributedStringWithAttachment:(NSTextAttachment *)(yearAttchment)];
  63. //用户名
  64. NSRange redRange = NSMakeRange(0, _model.userName.length+1);
  65. if ([_model.titleColor isEqual:@"userLogin"]){
  66. self.chatLabel.textColor = RGB_COLOR(@"#c7c9c7", 1);
  67. }else{
  68. self.chatLabel.textColor = [UIColor whiteColor];
  69. }
  70. if ([_model.isAnchor isEqual:@"1"]) {
  71. [noteStr addAttribute:NSForegroundColorAttributeName value:Pink_Cor range:redRange];
  72. }else{
  73. [noteStr addAttribute:NSForegroundColorAttributeName value:Pink_Cor range:redRange];
  74. }
  75. /*
  76. 0 青蛙
  77. 1 猴子
  78. 2 小红花
  79. 3 小黄花
  80. 4 心
  81. */
  82. if ([_model.titleColor isEqual:@"light0"])//青蛙
  83. {
  84. self.chatLabel.textColor = RGB_COLOR(@"#c7c9c7", 1);
  85. // 添加表情
  86. NSTextAttachment *attch = [[NSTextAttachment alloc] init];
  87. // 表情图片
  88. attch.image = [UIImage imageNamed:@"plane_heart_cyan.png"];
  89. // 设置图片大小
  90. attch.bounds = CGRectMake(0,-4,17,17);
  91. NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
  92. [noteStr appendAttributedString:string];
  93. }
  94. else if ([_model.titleColor isEqual:@"light1"])//猴子
  95. {
  96. self.chatLabel.textColor = RGB_COLOR(@"#c7c9c7", 1);
  97. // 添加表情
  98. NSTextAttachment *attch = [[NSTextAttachment alloc] init];
  99. // 表情图片
  100. attch.image = [UIImage imageNamed:@"plane_heart_pink.png"];
  101. // 设置图片大小
  102. attch.bounds = CGRectMake(0,-4,17,17);
  103. NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
  104. [noteStr appendAttributedString:string];
  105. }
  106. else if ([_model.titleColor isEqual:@"light2"])//小红花
  107. {
  108. self.chatLabel.textColor = RGB_COLOR(@"#c7c9c7", 1);
  109. // 添加表情
  110. NSTextAttachment *attch = [[NSTextAttachment alloc] init];
  111. // 表情图片
  112. attch.image = [UIImage imageNamed:@"plane_heart_red.png"];
  113. // 设置图片大小
  114. attch.bounds = CGRectMake(0,-4,17,17);
  115. NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
  116. [noteStr appendAttributedString:string];
  117. }
  118. else if ([_model.titleColor isEqual:@"light3"])//小黄花
  119. {
  120. self.chatLabel.textColor = RGB_COLOR(@"#c7c9c7", 1);
  121. // 添加表情
  122. NSTextAttachment *attch = [[NSTextAttachment alloc] init];
  123. // 表情图片
  124. attch.image = [UIImage imageNamed:@"plane_heart_yellow.png"];
  125. // 设置图片大小
  126. attch.bounds = CGRectMake(0,-4, 17, 17);
  127. NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
  128. [noteStr appendAttributedString:string];
  129. }
  130. else if ([_model.titleColor isEqual:@"light4"])//心
  131. {
  132. self.chatLabel.textColor = RGB_COLOR(@"#c7c9c7", 1);
  133. // 添加表情
  134. NSTextAttachment *attch = [[NSTextAttachment alloc] init];
  135. // 表情图片
  136. attch.image = [UIImage imageNamed:@"plane_heart_heart"];
  137. // 设置图片大小
  138. attch.bounds = CGRectMake(0,-4, 17, 17);
  139. NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
  140. [noteStr appendAttributedString:string];
  141. }
  142. //插入守护
  143. if ([_model.guard_type isEqual:@"1"]) {
  144. [noteStr insertAttributedString:speaceString atIndex:0];//插入到第几个下标
  145. [noteStr insertAttributedString:shouString atIndex:0];//插入到第几个下标
  146. }
  147. if ([_model.guard_type isEqual:@"2"]) {
  148. [noteStr insertAttributedString:speaceString atIndex:0];//插入到第几个下标
  149. [noteStr insertAttributedString:yearString atIndex:0];//插入到第几个下标
  150. }
  151. //插入管理图标
  152. if ([_model.isAdmin isEqual:@"1"]) {
  153. [noteStr insertAttributedString:speaceString atIndex:0];//插入到第几个下标
  154. [noteStr insertAttributedString:adminString atIndex:0];//插入到第几个下标
  155. }
  156. //插入VIP图标
  157. if ([_model.vip_type isEqual:@"1"]) {
  158. [noteStr insertAttributedString:speaceString atIndex:0];//插入到第几个下标
  159. [noteStr insertAttributedString:vipString atIndex:0];//插入到第几个下标
  160. }
  161. [noteStr insertAttributedString:speaceString atIndex:0];//插入到第几个下标
  162. }
  163. [self.chatLabel setAttributedText:noteStr];
  164. }
  165. @end