WFCUNewFriendTableViewCell.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // NewFriendTableViewCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/10/28.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUNewFriendTableViewCell.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import <SDWebImage/SDWebImage.h>
  11. #import "UIFont+YH.h"
  12. #import "UIColor+YH.h"
  13. @interface WFCUNewFriendTableViewCell ()
  14. @end
  15. @implementation WFCUNewFriendTableViewCell
  16. - (void)awakeFromNib {
  17. [super awakeFromNib];
  18. // Initialization code
  19. }
  20. - (void)layoutSubviews {
  21. [super layoutSubviews];
  22. self.portraitView.frame = CGRectMake(16, (self.frame.size.height - 40) / 2.0, 40, 40);
  23. self.nameLabel.frame = CGRectMake(16 + 40 + 11, (self.frame.size.height - 16) / 2.0, [UIScreen mainScreen].bounds.size.width - 64, 16);
  24. }
  25. - (void)onFriendRequestUpdated:(NSNotification *)notification {
  26. [self updateBubbleNumber];
  27. }
  28. - (void)updateBubbleNumber {
  29. int unreadCount = [[WFCCIMService sharedWFCIMService] getUnreadFriendRequestStatus];
  30. if (unreadCount) {
  31. self.bubbleView.hidden = NO;
  32. [self.bubbleView setBubbleTipNumber:unreadCount];
  33. } else {
  34. self.bubbleView.hidden = YES;
  35. }
  36. }
  37. - (void)refresh {
  38. [[NSNotificationCenter defaultCenter] removeObserver:self];
  39. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFriendRequestUpdated:) name:kFriendRequestUpdated object:nil];
  40. [self updateBubbleNumber];
  41. }
  42. - (BubbleTipView *)bubbleView {
  43. if (!_bubbleView) {
  44. if (self.portraitView) {
  45. _bubbleView = [[BubbleTipView alloc] initWithSuperView:self.contentView];
  46. _bubbleView.hidden = YES;
  47. }
  48. }
  49. return _bubbleView;
  50. }
  51. - (UIImageView *)portraitView {
  52. if (!_portraitView) {
  53. _portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(16, 10, 40, 40)];
  54. _portraitView.layer.masksToBounds = YES;
  55. _portraitView.layer.cornerRadius = 4.f;
  56. [self.contentView addSubview:_portraitView];
  57. }
  58. return _portraitView;
  59. }
  60. - (UILabel *)nameLabel {
  61. if (!_nameLabel) {
  62. _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(16 + 40 + 11, 19, [UIScreen mainScreen].bounds.size.width - 64, 16)];
  63. _nameLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:15];
  64. _nameLabel.textColor = [UIColor colorWithHexString:@"0x1d1d1d"];
  65. [self.contentView addSubview:_nameLabel];
  66. }
  67. return _nameLabel;
  68. }
  69. - (void)dealloc {
  70. [[NSNotificationCenter defaultCenter] removeObserver:self];
  71. }
  72. @end