Няма описание

FKCirDetailCommentCell.m 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // FKCircleCommentCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/6/15.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKCirDetailCommentCell.h"
  9. #import "FKCircleDetailViewModel.h"
  10. #import "FKCirAllCommentViewModel.h"
  11. @interface FKCirDetailCommentCell ()
  12. @property (nonatomic, strong) UIImageView *iconImgView;
  13. @property (nonatomic, strong) UIView *bottomLine;
  14. @property (nonatomic, strong) UILabel *nameLabel;
  15. @property (nonatomic, strong) UILabel *timeLabel;
  16. @property (nonatomic, strong) UILabel *commentLabel;
  17. @end
  18. @implementation FKCirDetailCommentCell
  19. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  20. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  21. [self addAllSubviews];
  22. self.selectionStyle = UITableViewCellSelectionStyleNone;
  23. self.contentView.backgroundColor = [UIColor whiteColor];
  24. }
  25. return self;
  26. }
  27. - (void)addAllSubviews{
  28. [self.contentView addSubview:self.iconImgView];
  29. [self.contentView addSubview:self.nameLabel];
  30. [self.contentView addSubview:self.timeLabel];
  31. [self.contentView addSubview:self.commentLabel];
  32. [self.contentView addSubview:self.bottomLine];
  33. [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.left.equalTo(self.contentView).offset(15);
  35. make.top.equalTo(self.contentView).offset(10);
  36. make.width.height.mas_equalTo(30);
  37. }];
  38. [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.centerY.equalTo(self.iconImgView);
  40. make.left.equalTo(self.iconImgView.mas_right).offset(16);
  41. }];
  42. [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.right.equalTo(self.contentView).offset(- 15);
  44. make.centerY.equalTo(self.nameLabel);
  45. }];
  46. [self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.left.equalTo(self.nameLabel);
  48. make.top.equalTo(self.nameLabel.mas_bottom).offset(8);
  49. make.right.equalTo(self.contentView).offset(- 15);
  50. }];
  51. [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.left.equalTo(self.commentLabel);
  53. make.right.bottom.equalTo(self.contentView);
  54. make.height.equalTo(@0.5);
  55. }];
  56. }
  57. - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
  58. if ([viewModel isKindOfClass:[FKCircleDetailViewModel class]]) {
  59. FKCircleDetailViewModel *cirViewModel = (FKCircleDetailViewModel *)viewModel;
  60. FKCircleCommentItem *commentItem = [cirViewModel.dataItem commentItemAtIndex:indexPath.row];
  61. if (commentItem){
  62. [self.iconImgView setImageWithURL:commentItem.headPicUrl cdnWidth:60];
  63. self.nameLabel.attributedText = [commentItem getRealCommentTitle];
  64. self.commentLabel.text = commentItem.content;
  65. self.timeLabel.text = [FLStringHelper convertToCommonFormateFromString:commentItem.createTime baseTime:cirViewModel.dataItem.serveTime];
  66. }
  67. }
  68. if ([viewModel isKindOfClass:[FKCirAllCommentViewModel class]]){
  69. FKCirAllCommentViewModel *commentViewModel = (FKCirAllCommentViewModel *)viewModel;
  70. FKCircleCommentItem *commentItem = [commentViewModel commentItemAtIndex:indexPath.row];
  71. if (commentItem){
  72. [self.iconImgView setImageWithURL:commentItem.headPicUrl cdnWidth:60];
  73. self.nameLabel.attributedText = [commentItem getRealCommentTitle];
  74. self.commentLabel.text = commentItem.content;
  75. self.timeLabel.text = [FLStringHelper convertToCommonFormateFromString:commentItem.createTime baseTime:commentViewModel.serveTime];
  76. }
  77. }
  78. }
  79. + (CGFloat)cellHeightForCommentText:(NSString *)text{
  80. CGRect rect = [FLStringHelper rectOfString:text
  81. font:[UIFont systemFontOfSize:14]
  82. width:UISCREENWIDTH - 76];
  83. CGFloat otherHeight = 52;
  84. if (rect.size.height == 0) return otherHeight;
  85. return rect.size.height + otherHeight;
  86. }
  87. #pragma mark - property
  88. - (UIImageView *)iconImgView{
  89. if (_iconImgView == nil) {
  90. _iconImgView = [[UIImageView alloc]init];
  91. _iconImgView.layer.cornerRadius = 15;
  92. _iconImgView.layer.masksToBounds = YES;
  93. }
  94. return _iconImgView;
  95. }
  96. - (UILabel *)nameLabel{
  97. if (_nameLabel == nil) {
  98. _nameLabel = [[UILabel alloc]init];
  99. _nameLabel.backgroundColor = [UIColor clearColor];
  100. _nameLabel.font = [UIFont systemFontOfSize:14];
  101. _nameLabel.textColor = UIColorFromRGB(0x333333);
  102. _nameLabel.textAlignment = NSTextAlignmentLeft;
  103. }
  104. return _nameLabel;
  105. }
  106. - (UILabel *)timeLabel{
  107. if (_timeLabel == nil) {
  108. _timeLabel = [[UILabel alloc]init];
  109. _timeLabel.backgroundColor = [UIColor clearColor];
  110. _timeLabel.font = [UIFont systemFontOfSize:14];
  111. _timeLabel.textColor = UIColorFromRGB(0x999999);
  112. _timeLabel.textAlignment = NSTextAlignmentRight;
  113. }
  114. return _timeLabel;
  115. }
  116. - (UILabel *)commentLabel{
  117. if (_commentLabel == nil) {
  118. _commentLabel = [[UILabel alloc]init];
  119. _commentLabel.backgroundColor = [UIColor clearColor];
  120. _commentLabel.font = [UIFont systemFontOfSize:14];
  121. _commentLabel.textColor = UIColorFromRGB(0x999999);
  122. _commentLabel.numberOfLines = 0;
  123. }
  124. return _commentLabel;
  125. }
  126. - (UIView *)bottomLine{
  127. if (_bottomLine == nil) {
  128. _bottomLine = [[UIView alloc]init];
  129. _bottomLine.backgroundColor = UIColorFromRGB(0xf4f4f4);
  130. }
  131. return _bottomLine;
  132. }
  133. @end