WFCUCardCell.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // WFCUCardCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/9/1.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUCardCell.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import "WFCUUtilities.h"
  11. #import "UILabel+YBAttributeTextTapAction.h"
  12. #import <SDWebImage/SDWebImage.h>
  13. #define TEXT_TOP_PADDING 6
  14. #define TEXT_BUTTOM_PADDING 6
  15. #define TEXT_LEFT_PADDING 8
  16. #define TEXT_RIGHT_PADDING 8
  17. #define TEXT_LABEL_TOP_PADDING TEXT_TOP_PADDING + 4
  18. #define TEXT_LABEL_BUTTOM_PADDING TEXT_BUTTOM_PADDING + 4
  19. #define TEXT_LABEL_LEFT_PADDING 30
  20. #define TEXT_LABEL_RIGHT_PADDING 30
  21. @interface WFCUCardCell ()
  22. @property (nonatomic, strong)UIImageView *cardPortrait;
  23. @property (nonatomic, strong)UILabel *cardDisplayName;
  24. @property (nonatomic, strong)UILabel *cardName;
  25. @property (nonatomic, strong)UIView *cardSeparateLine;
  26. @property (nonatomic, strong)UILabel *cardHint;
  27. @end
  28. @implementation WFCUCardCell
  29. + (CGSize)sizeForClientArea:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
  30. return CGSizeMake(width, 100);
  31. }
  32. - (void)setModel:(WFCUMessageModel *)model {
  33. [super setModel:model];
  34. WFCCCardMessageContent *content = (WFCCCardMessageContent *)model.message.content;
  35. self.cardDisplayName.text = content.displayName;
  36. self.cardName.text = content.name;
  37. [self.cardPortrait sd_setImageWithURL:[NSURL URLWithString:content.portrait] placeholderImage:[UIImage imageNamed:@"PersonalChat"]];
  38. [self cardSeparateLine];
  39. [self cardHint];
  40. }
  41. - (UIImageView *)cardPortrait {
  42. if (!_cardPortrait) {
  43. _cardPortrait = [[UIImageView alloc] initWithFrame:CGRectMake(8, 8, 56, 56)];
  44. [self.contentArea addSubview:_cardPortrait];
  45. }
  46. return _cardPortrait;
  47. }
  48. - (UILabel *)cardDisplayName {
  49. if (!_cardDisplayName) {
  50. CGRect bounds = self.contentArea.bounds;
  51. _cardDisplayName = [[UILabel alloc] initWithFrame:CGRectMake(72, 10, bounds.size.width - 72 - 8, 24)];
  52. [self.contentArea addSubview:_cardDisplayName];
  53. }
  54. return _cardDisplayName;
  55. }
  56. - (UILabel *)cardName {
  57. if (!_cardName) {
  58. CGRect bounds = self.contentArea.bounds;
  59. _cardName = [[UILabel alloc] initWithFrame:CGRectMake(72, 40, bounds.size.width - 72 - 8, 18)];
  60. _cardName.font = [UIFont systemFontOfSize:14];
  61. _cardName.textColor = [UIColor grayColor];
  62. [self.contentArea addSubview:_cardName];
  63. }
  64. return _cardName;
  65. }
  66. - (UIView *)cardSeparateLine {
  67. if (!_cardSeparateLine) {
  68. CGRect bounds = self.contentArea.bounds;
  69. _cardSeparateLine = [[UIView alloc] initWithFrame:CGRectMake(8, 78, bounds.size.width - 8 - 8, 1)];
  70. _cardSeparateLine.backgroundColor = [UIColor grayColor];
  71. [self.contentArea addSubview:_cardSeparateLine];
  72. }
  73. return _cardSeparateLine;
  74. }
  75. - (UILabel *)cardHint {
  76. if (!_cardHint) {
  77. _cardHint = [[UILabel alloc] initWithFrame:CGRectMake(8, 84, 80, 12)];
  78. _cardHint.font = [UIFont systemFontOfSize:10];
  79. _cardHint.text = @"个人名片";
  80. _cardHint.textColor = [UIColor grayColor];
  81. [self.contentArea addSubview:_cardHint];
  82. }
  83. return _cardHint;
  84. }
  85. @end