2
0

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