ChatMsgSearchReseltContentCell.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // ChatMsgSearchReseltContentCell.m
  3. // smartRhino
  4. //
  5. // Created by armin on 2019/11/4.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "ChatMsgSearchReseltContentCell.h"
  9. @implementation ChatMsgSearchReseltContentCell
  10. - (void)awakeFromNib {
  11. [super awakeFromNib];
  12. // Initialization code
  13. }
  14. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  15. [super setSelected:selected animated:animated];
  16. // Configure the view for the selected state
  17. }
  18. + (CGFloat)configCell0Height{
  19. return 64;
  20. }
  21. + (ChatMsgSearchReseltContentCell *)configCell0:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  22. static NSString *cellIdentifer = @"ChatMsgSearchReseltContentCell0";
  23. ChatMsgSearchReseltContentCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  24. if (cell == nil) {
  25. cell = [[[NSBundle mainBundle] loadNibNamed:@"ChatMsgSearchReseltContentCell" owner:nil options:nil] objectAtIndex:0];
  26. }
  27. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  28. [cell.cell0ShowImgView setRadius:4 corners:UIRectCornerAllCorners];
  29. cell.cell0IntroLabel.textColor = RGB(153, 153, 153);
  30. return cell;
  31. }
  32. - (void)bindData:(ChatMsgSearchModelSub *)model WithKeyStr:(nonnull NSString *)keyStr {
  33. // 0:全部 1 通知 2 通讯录 3 单聊 4群聊 5 文章 6 站内信 7话题 (后台定义)
  34. // 全部
  35. // 消息(单聊 群聊)
  36. // 话题
  37. // 小组 ??
  38. // 通知
  39. // 站内信
  40. // 通讯录
  41. model.SearchType = 3;
  42. // 通讯录样式
  43. if (model.SearchType == 6 || model.SearchType == 3) {
  44. [self.type7NameLabel setHidden:NO];
  45. [self.cell0TitleLabel setHidden:YES];
  46. [self.cell0IntroLabel setHidden:YES];
  47. } else {
  48. [self.type7NameLabel setHidden:YES];
  49. [self.cell0TitleLabel setHidden:NO];
  50. [self.cell0IntroLabel setHidden:NO];
  51. }
  52. // 消息样式
  53. if (model.SearchType == 1) {
  54. self.cell0IntroLabel.textColor = kColorFromRGB(0x3979D3);
  55. } else {
  56. self.cell0IntroLabel.textColor = kColorFromRGB(0x999999);
  57. }
  58. [self.cell0ShowImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  59. switch (model.SearchType) {
  60. case 1:{
  61. self.cell0TitleLabel.text = model.Title;
  62. self.cell0IntroLabel.text = [NSString stringWithFormat:@"%@条相关记录",@(1)];
  63. self.cell0TypeLabel.text = @"消息";
  64. }
  65. break;
  66. case 2:{
  67. self.cell0IntroLabel.text = [NSString stringWithFormat:@"%@ %@",model.Name,[ZYCTool yearMonthAndDayHourMinuesSecond:model.CreatedDate]];
  68. // 关键字变色
  69. self.cell0TitleLabel.attributedText = [self changeText:model.Title KeyWordL:keyStr KeyWordColor:RGB(234, 55, 41)];
  70. self.cell0TypeLabel.text = @"话题";
  71. }
  72. break;
  73. case 3:{
  74. self.type7NameLabel.attributedText = [self changeText:model.Title KeyWordL:keyStr KeyWordColor:RGB(234, 55, 41)];
  75. [self.cell0ShowImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  76. self.cell0TypeLabel.text = @"小组";
  77. }
  78. break;
  79. case 4:{
  80. self.cell0TypeLabel.text = @"通知";
  81. // 关键字变色
  82. self.cell0TitleLabel.attributedText = [self changeText:model.Title KeyWordL:keyStr KeyWordColor:RGB(234, 55, 41)];
  83. self.cell0IntroLabel.text = model.Name;
  84. // todo 已读未读
  85. }
  86. break;
  87. case 5:{
  88. self.cell0IntroLabel.text = model.Name;
  89. // todo 已读未读
  90. self.cell0TypeLabel.text = @"站内信";
  91. self.cell0TitleLabel.attributedText = [self changeText:model.Title KeyWordL:keyStr KeyWordColor:RGB(234, 55, 41)];
  92. }
  93. break;
  94. case 6:{
  95. self.type7NameLabel.attributedText = [self changeText:model.Title KeyWordL:keyStr KeyWordColor:RGB(234, 55, 41)];
  96. [self.cell0ShowImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  97. self.cell0TypeLabel.text = @"通讯录";
  98. }
  99. break;
  100. default:
  101. self.type7NameLabel.text = @"";
  102. [self.cell0ShowImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  103. self.cell0TypeLabel.text = @"";
  104. self.cell0TitleLabel.text = @"";
  105. self.cell0IntroLabel.text = @"";
  106. break;
  107. }
  108. }
  109. // 关键字变色
  110. - (NSAttributedString *)changeText:(NSString *)text KeyWordL:(NSString *)keyWord KeyWordColor:(UIColor *)color {
  111. NSString *string1 = text;
  112. NSString *string2 = keyWord;
  113. NSArray *array=[string1 componentsSeparatedByString:string2];
  114. NSMutableArray *arrayOfLocation=[NSMutableArray new];
  115. int d=0;
  116. for (int i=0; i<array.count-1; i++) {
  117. NSString *string=array[i];
  118. NSNumber *number=[NSNumber numberWithInt:d+=string.length];
  119. d+=string2.length;
  120. [arrayOfLocation addObject:number];
  121. }
  122. // 关键字变色
  123. NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:text];
  124. for (int i = 0; i < arrayOfLocation.count; i ++) {
  125. NSInteger loc = [arrayOfLocation[i] integerValue];
  126. NSRange range = NSMakeRange(loc, keyWord.length);
  127. [attrString addAttribute:(NSString *)NSForegroundColorAttributeName
  128. value:RGB(234, 55, 41)
  129. range:range];
  130. }
  131. return attrString;
  132. }
  133. @end