ComentSubCell.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // ComentSubCell.m
  3. // smartRhino
  4. //
  5. // Created by tederen on 2019/10/29.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "ComentSubCell.h"
  9. #import "CommentSubModel.h"
  10. @interface ComentSubCell ()
  11. @property (nonatomic, strong) UIImageView *portraitImgVi;
  12. @property (nonatomic, strong) UILabel *nameLabel;
  13. @property (nonatomic, strong) UILabel *secondNameLabel;
  14. @property (nonatomic, strong) UILabel *timeLabel;
  15. @property (nonatomic, strong) UILabel *contentLabel;
  16. @property (nonatomic, strong) UILabel *huifuLabel;
  17. @end
  18. @implementation ComentSubCell
  19. - (void)awakeFromNib {
  20. [super awakeFromNib];
  21. // Initialization code
  22. }
  23. - (void)loadCommentSubModelData:(CommentSubModel *)model{
  24. CGFloat herizonSpace = 8;
  25. CGFloat leftMargin = 0;
  26. CGFloat rightMargin = 21;
  27. // CGFloat verticalSpace = 14.5;
  28. if (!ISEmptyString(model.ReplyName)) {
  29. _nameLabel.text = model.Name;
  30. _nameLabel.textColor = UIColorHex(1F87DB);
  31. [ZYCTool setLabel:_nameLabel withSpace:10 withFont:[UIFont systemFontOfSize:17.f] setLineSpace:0 setTextSpace:2];
  32. CGSize nameSize = [_nameLabel sizeThatFits:CGSizeMake(kGXScreenWidth - 68 ,MAXFLOAT)];
  33. _nameLabel.frame = CGRectMake(leftMargin,2,nameSize.width, nameSize.height);
  34. _huifuLabel.text = @"回复";
  35. _huifuLabel.textColor = UIColorHex(636363);
  36. [ZYCTool setLabel:_huifuLabel withSpace:10 withFont:[UIFont systemFontOfSize:17.f] setLineSpace:0 setTextSpace:2];
  37. CGSize huifuSize = [_huifuLabel sizeThatFits:CGSizeZero];
  38. _huifuLabel.frame = CGRectMake(CGRectGetMaxX(_nameLabel.frame)+herizonSpace,2,huifuSize.width,huifuSize.height);
  39. _secondNameLabel.text = [NSString stringWithFormat:@"%@:",model.ReplyName];
  40. _secondNameLabel.textColor = UIColorHex(1F87DB);
  41. [ZYCTool setLabel:_secondNameLabel withSpace:10 withFont:[UIFont systemFontOfSize:17.f] setLineSpace:0 setTextSpace:2];
  42. CGSize secondNameSize = [_secondNameLabel sizeThatFits:CGSizeMake(kGXScreenWidth - 68 ,MAXFLOAT)];
  43. _secondNameLabel.frame = CGRectMake(CGRectGetMaxX(_huifuLabel.frame)+herizonSpace,2,secondNameSize.width, secondNameSize.height);
  44. _contentLabel.text = model.Content;
  45. [ZYCTool setLabel:_contentLabel withSpace:10 withFont:[UIFont systemFontOfSize:17.f] setLineSpace:0 setTextSpace:2];
  46. CGSize contentSize = [_contentLabel sizeThatFits:CGSizeMake(kGXScreenWidth - leftMargin -rightMargin ,MAXFLOAT)];
  47. _contentLabel.frame = CGRectMake(CGRectGetMaxX(_secondNameLabel.frame)+ herizonSpace,2,contentSize.width, contentSize.height);
  48. _timeLabel.text = model.time;
  49. _timeLabel.font = [UIFont systemFontOfSize:16.f];
  50. CGSize timeSize = [_timeLabel sizeThatFits:CGSizeMake(kGXScreenWidth - 68 - 21,MAXFLOAT)];
  51. _timeLabel.frame = CGRectMake(CGRectGetMaxX(_contentLabel.frame) + herizonSpace,2,timeSize.width, timeSize.height);
  52. if ([model.time isEqual: @"刚刚"]){
  53. _timeLabel.textColor = UIColorHex(E9382C);
  54. }
  55. // CGFloat width_o = kGXScreenWidth - leftMargin - rightMargin - nameSize.width - herizonSpace - huifuSize.width - herizonSpace - secondNameSize.width - herizonSpace - contentSize.width; // 剩余宽度
  56. // if (width_o == 0){
  57. // _
  58. //
  59. // }else if (width_o >= 0){
  60. //
  61. // }else{
  62. //
  63. // }
  64. }else{
  65. _nameLabel.text = [NSString stringWithFormat:@"%@:",model.Name];
  66. _nameLabel.textColor = UIColorHex(1F87DB);
  67. [ZYCTool setLabel:_nameLabel withSpace:10 withFont:[UIFont systemFontOfSize:17.f] setLineSpace:0 setTextSpace:2];
  68. CGSize nameSize = [_nameLabel sizeThatFits:CGSizeMake(kGXScreenWidth - leftMargin - rightMargin ,MAXFLOAT)];
  69. _nameLabel.frame = CGRectMake(leftMargin,0,nameSize.width, nameSize.height);
  70. _contentLabel.text = model.Content;
  71. [ZYCTool setLabel:_contentLabel withSpace:10 withFont:[UIFont systemFontOfSize:17.f] setLineSpace:0 setTextSpace:2];
  72. CGSize contentSize = [_contentLabel sizeThatFits:CGSizeMake(kGXScreenWidth - leftMargin -rightMargin ,MAXFLOAT)];
  73. _contentLabel.frame = CGRectMake(CGRectGetMaxX(_nameLabel.frame)+ herizonSpace,0,contentSize.width, contentSize.height);
  74. CGFloat width_o = kGXScreenWidth - leftMargin - rightMargin - nameSize.width - herizonSpace - contentSize.width - herizonSpace; // 剩余宽度
  75. _timeLabel.text = model.time;
  76. CGSize timeSize = [_timeLabel sizeThatFits:CGSizeMake(kGXScreenWidth - 68 - 21,MAXFLOAT)];
  77. if (width_o < timeSize.width ) {
  78. _timeLabel.frame = CGRectMake(leftMargin,CGRectGetMaxY(_contentLabel.frame)-6,timeSize.width, timeSize.height);
  79. }else{
  80. _timeLabel.frame = CGRectMake(CGRectGetMaxX(_contentLabel.frame) + herizonSpace,0,timeSize.width, timeSize.height);
  81. }
  82. }
  83. }
  84. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  85. {
  86. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  87. if (self) {
  88. // Initialization code
  89. [self addSubview:self.nameLabel];
  90. [self addSubview:self.secondNameLabel];
  91. [self addSubview:self.huifuLabel];
  92. [self addSubview:self.timeLabel];
  93. [self addSubview:self.contentLabel];
  94. }
  95. return self;
  96. }
  97. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  98. [super setSelected:selected animated:animated];
  99. // Configure the view for the selected state
  100. }
  101. - (UILabel *)nameLabel {
  102. if (!_nameLabel) {
  103. _nameLabel = [UILabel new];
  104. _nameLabel.font = [UIFont systemFontOfSize:15.f];
  105. _nameLabel.textColor = k6;
  106. _nameLabel.text = @"占位";
  107. }
  108. return _nameLabel;
  109. }
  110. - (UILabel *)secondNameLabel{
  111. if(!_secondNameLabel){
  112. _secondNameLabel = [UILabel new];
  113. _secondNameLabel.font = [UIFont systemFontOfSize:15.f];
  114. _secondNameLabel.textColor = k6;
  115. _secondNameLabel.text = @"占位";
  116. }
  117. return _secondNameLabel;
  118. }
  119. - (UILabel *)timeLabel {
  120. if (!_timeLabel) {
  121. _timeLabel = [UILabel new];
  122. _timeLabel.font = [UIFont systemFontOfSize:12.f];
  123. _timeLabel.textColor = k9;
  124. _timeLabel.text = @"占位";
  125. }
  126. return _timeLabel;
  127. }
  128. - (UILabel *)contentLabel {
  129. if (!_contentLabel) {
  130. _contentLabel = [UILabel new];
  131. _contentLabel.numberOfLines = 0;
  132. _contentLabel.font = [UIFont systemFontOfSize:15.f];
  133. _contentLabel.textColor = k6;
  134. _contentLabel.text = @"占位";
  135. }
  136. return _contentLabel;
  137. }
  138. - (UILabel *)huifuLabel{
  139. if(!_huifuLabel){
  140. _huifuLabel = [[UILabel alloc]init];
  141. _huifuLabel.font = [UIFont systemFontOfSize:15.f];
  142. _huifuLabel.textColor = k9;
  143. _huifuLabel.text = @"占位";
  144. }
  145. return _huifuLabel;
  146. }
  147. @end