2
0

WFCUSearchGroupTableViewCell.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // WFCUSearchGroupTableViewCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/9/13.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUSearchGroupTableViewCell.h"
  9. #import "SDWebImage.h"
  10. @interface WFCUSearchGroupTableViewCell()
  11. @property (strong, nonatomic) UIImageView *portrait;
  12. @property (strong, nonatomic) UILabel *name;
  13. @property (strong, nonatomic) UILabel *haveMember;
  14. @end
  15. @implementation WFCUSearchGroupTableViewCell
  16. - (void)awakeFromNib {
  17. [super awakeFromNib];
  18. // Initialization code
  19. }
  20. - (UIImageView *)portrait {
  21. if (!_portrait) {
  22. _portrait = [[UIImageView alloc] initWithFrame:CGRectMake(8, 8, 52, 52)];
  23. [self.contentView addSubview:_portrait];
  24. }
  25. return _portrait;
  26. }
  27. - (UILabel *)name {
  28. if (!_name) {
  29. _name = [[UILabel alloc] initWithFrame:CGRectMake(72, 12, [UIScreen mainScreen].bounds.size.width - 64, 20)];
  30. [_name setFont:[UIFont systemFontOfSize:18]];
  31. [self.contentView addSubview:_name];
  32. }
  33. return _name;
  34. }
  35. - (UILabel *)haveMember {
  36. if (!_haveMember) {
  37. _haveMember = [[UILabel alloc] initWithFrame:CGRectMake(72, 36, [UIScreen mainScreen].bounds.size.width - 64, 19)];
  38. [_haveMember setFont:[UIFont systemFontOfSize:14]];
  39. _haveMember.textColor = [UIColor grayColor];
  40. [self.contentView addSubview:_haveMember];
  41. }
  42. return _haveMember;
  43. }
  44. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  45. [super setSelected:selected animated:animated];
  46. // Configure the view for the selected state
  47. }
  48. - (void)setGroupSearchInfo:(WFCCGroupSearchInfo *)groupSearchInfo {
  49. _groupSearchInfo = groupSearchInfo;
  50. WFCCGroupInfo *groupInfo = groupSearchInfo.groupInfo;
  51. if (groupInfo.name.length == 0) {
  52. self.name.text = [NSString stringWithFormat:@"Group<%@>", groupInfo.target];
  53. } else {
  54. self.name.text = [NSString stringWithFormat:@"%@(%d)", groupInfo.name, (int)groupInfo.memberCount];
  55. }
  56. if (groupSearchInfo.marchType > 0) {
  57. NSMutableAttributedString *string;
  58. for (NSString *memberId in groupSearchInfo.marchedMemberNames) {
  59. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:memberId refresh:NO];
  60. if (userInfo) {
  61. string = [[NSMutableAttributedString alloc] initWithString:userInfo.displayName];
  62. [string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, string.length)];
  63. [string addAttribute:NSUnderlineStyleAttributeName value:@YES range:NSMakeRange(0, string.length)];
  64. break;
  65. }
  66. }
  67. if (string == nil) {
  68. string = [[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"用户<%@>", groupSearchInfo.marchedMemberNames[0]]] mutableCopy];
  69. }
  70. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:@"群成员含:"];
  71. [attrStr appendAttributedString:string];
  72. if (groupSearchInfo.marchedMemberNames.count > 1) {
  73. [attrStr appendAttributedString:[[NSAttributedString alloc] initWithString:@"等"]];
  74. }
  75. self.haveMember.attributedText = attrStr;
  76. } else {
  77. NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:groupSearchInfo.keyword];
  78. [string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, string.length)];
  79. [string addAttribute:NSUnderlineStyleAttributeName value:@YES range:NSMakeRange(0, string.length)];
  80. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:@"群名包含:"];
  81. [attrStr appendAttributedString:string];
  82. self.haveMember.attributedText = attrStr;
  83. }
  84. [self.portrait sd_setImageWithURL:[NSURL URLWithString:groupInfo.portrait] placeholderImage:[UIImage imageNamed:@"group_default_portrait"]];
  85. }
  86. @end