WFCUSearchGroupTableViewCell.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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/SDWebImage.h>
  10. #import "UIFont+YH.h"
  11. #import "UIColor+YH.h"
  12. @interface WFCUSearchGroupTableViewCell()
  13. @property (strong, nonatomic) UIImageView *portrait;
  14. @property (strong, nonatomic) UILabel *name;
  15. @property (strong, nonatomic) UILabel *haveMember;
  16. @end
  17. @implementation WFCUSearchGroupTableViewCell
  18. - (void)awakeFromNib {
  19. [super awakeFromNib];
  20. // Initialization code
  21. }
  22. - (void)layoutSubviews {
  23. [super layoutSubviews];
  24. CGFloat postionY = (self.frame.size.height - 40) / 2.0;
  25. self.portrait.frame = CGRectMake(16, postionY, 40, 40);
  26. self.name.frame = CGRectMake(10 + 40 + 20, postionY, [UIScreen mainScreen].bounds.size.width - (10 + 40 + 20), 20);
  27. postionY += 15 + 8;
  28. self.haveMember.frame = CGRectMake(10 + 40 + 20, postionY, [UIScreen mainScreen].bounds.size.width - (10 + 40 + 20), 19);
  29. }
  30. - (UIImageView *)portrait {
  31. if (!_portrait) {
  32. _portrait = [UIImageView new];
  33. _portrait.layer.cornerRadius = 4;
  34. _portrait.layer.masksToBounds = YES;
  35. [self.contentView addSubview:_portrait];
  36. }
  37. return _portrait;
  38. }
  39. - (UILabel *)name {
  40. if (!_name) {
  41. _name = [UILabel new];
  42. [_name setFont:[UIFont pingFangSCWithWeight:FontWeightStyleRegular size:15]];
  43. _name.textColor = [UIColor colorWithHexString:@"0x1d1d1d"];
  44. [self.contentView addSubview:_name];
  45. }
  46. return _name;
  47. }
  48. - (UILabel *)haveMember {
  49. if (!_haveMember) {
  50. _haveMember = [UILabel new];
  51. [_haveMember setFont:[UIFont pingFangSCWithWeight:FontWeightStyleRegular size:12]];
  52. _haveMember.textColor = [UIColor colorWithHexString:@"0xb3b3b3"];
  53. [self.contentView addSubview:_haveMember];
  54. }
  55. return _haveMember;
  56. }
  57. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  58. [super setSelected:selected animated:animated];
  59. // Configure the view for the selected state
  60. }
  61. - (void)setGroupSearchInfo:(WFCCGroupSearchInfo *)groupSearchInfo {
  62. _groupSearchInfo = groupSearchInfo;
  63. WFCCGroupInfo *groupInfo = groupSearchInfo.groupInfo;
  64. if (groupInfo.name.length == 0) {
  65. self.name.text = WFCString(@"GroupChat");
  66. } else {
  67. self.name.text = [NSString stringWithFormat:@"%@(%d)", groupInfo.name, (int)groupInfo.memberCount];
  68. }
  69. if (groupSearchInfo.marchType > 0) {
  70. NSMutableAttributedString *string;
  71. for (NSString *memberId in groupSearchInfo.marchedMemberNames) {
  72. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:memberId refresh:NO];
  73. if (userInfo) {
  74. string = [[NSMutableAttributedString alloc] initWithString:userInfo.displayName];
  75. [string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, string.length)];
  76. [string addAttribute:NSUnderlineStyleAttributeName value:@YES range:NSMakeRange(0, string.length)];
  77. break;
  78. }
  79. }
  80. if (string == nil) {
  81. string = [[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@<%@>", WFCString(@"User"), groupSearchInfo.marchedMemberNames[0]]] mutableCopy];
  82. }
  83. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:WFCString(@"GroupMemberNameMatch")];
  84. [attrStr appendAttributedString:string];
  85. if (groupSearchInfo.marchedMemberNames.count > 1) {
  86. [attrStr appendAttributedString:[[NSAttributedString alloc] initWithString:WFCString(@"Etc")]];
  87. }
  88. self.haveMember.attributedText = attrStr;
  89. } else {
  90. NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:groupSearchInfo.keyword];
  91. [string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, string.length)];
  92. [string addAttribute:NSUnderlineStyleAttributeName value:@YES range:NSMakeRange(0, string.length)];
  93. [string addAttribute:NSFontAttributeName value:[UIFont pingFangSCWithWeight:FontWeightStyleRegular size:12] range:NSMakeRange(0, string.length)];
  94. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:WFCString(@"GroupNameMatch")];
  95. [attrStr appendAttributedString:string];
  96. self.haveMember.attributedText = attrStr;
  97. }
  98. [self.portrait sd_setImageWithURL:[NSURL URLWithString:[groupInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[UIImage imageNamed:@"group_default_portrait"]];
  99. }
  100. @end