BGReplyCell.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // BGReplyCell.m
  3. // BuguLive
  4. //
  5. // Created by fanwe2014 on 2017/3/21.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "BGReplyCell.h"
  9. #import "CommentModel.h"
  10. @implementation BGReplyCell
  11. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  12. {
  13. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
  14. {
  15. self.contentView.bounds = [UIScreen mainScreen].bounds;
  16. [self creatMainView];
  17. }
  18. return self ;
  19. }
  20. - (void)creatMainView
  21. {
  22. self.headImgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 40, 40)];
  23. self.headImgView.userInteractionEnabled = YES;
  24. self.headImgView.layer.cornerRadius = 20;
  25. self.headImgView.layer.masksToBounds = YES;
  26. self.headImgView.image = kDefaultPreloadHeadImg;
  27. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imgViewTap:)];
  28. [self.headImgView addGestureRecognizer:tap];
  29. [self addSubview:self.headImgView];
  30. self.iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(40, 40, 10, 10)];
  31. [self addSubview:self.iconImgView];
  32. self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 10, kScreenW-200, 20)];
  33. self.nameLabel.textColor = kAppGrayColor1;
  34. self.nameLabel.font = [UIFont systemFontOfSize:14];
  35. self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  36. [self addSubview:self.nameLabel];
  37. self.replyLabel = [[UILabel alloc]init];
  38. self.replyLabel.textColor = RGB(153, 153, 153);
  39. self.replyLabel.font = [UIFont systemFontOfSize:11];
  40. self.replyLabel.numberOfLines = 0;
  41. [self addSubview:self.replyLabel];
  42. self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenW-110, 10, 100, 20)];
  43. self.timeLabel.textColor = RGB(153, 153, 153);
  44. self.timeLabel.textAlignment = NSTextAlignmentRight;
  45. self.timeLabel.font = [UIFont systemFontOfSize:11];
  46. [self addSubview:self.timeLabel];
  47. self.lineView = [[UIView alloc]init];
  48. self.lineView.backgroundColor = kAppSpaceColor2;
  49. [self addSubview:self.lineView];
  50. self.clearBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  51. self.clearBtn.backgroundColor = kClearColor;
  52. [self.clearBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  53. [self addSubview:self.clearBtn];
  54. self.nameBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  55. self.nameBtn.backgroundColor = kClearColor;
  56. self.nameBtn.tag = -1;
  57. [self.nameBtn addTarget:self action:@selector(clickNameString:) forControlEvents:UIControlEventTouchUpInside];
  58. [self addSubview:self.nameBtn];
  59. }
  60. - (CGFloat)creatCellWithModel:(CommentModel *)model andRow:(int)row
  61. {
  62. self.clearBtn.tag = row;
  63. [self.headImgView sd_setImageWithURL:[NSURL URLWithString:model.head_image] placeholderImage:kDefaultPreloadHeadImg];
  64. self.headImgView.contentMode = UIViewContentModeScaleAspectFill;
  65. self.headImgView.clipsToBounds = YES;
  66. self.headImgView.tag = row;
  67. // if ([model.is_authentication intValue] != 2)
  68. // {
  69. self.iconImgView.hidden = YES;
  70. // }
  71. // [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:model.v_icon] placeholderImage:kDefaultPreloadHeadImg];
  72. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:model.nick_name];
  73. self.nameLabel.attributedText = attr;
  74. self.timeLabel.text = model.left_time;
  75. NSString *nameString;
  76. if ([model.to_user_id intValue] > 0)
  77. {
  78. nameString = [NSString stringWithFormat:ASLocalizedString(@"回复 %@: %@"),model.to_nick_name,model.content];
  79. }else
  80. {
  81. nameString = [NSString stringWithFormat:@" %@",model.content];
  82. }
  83. NSMutableAttributedString *attr1 = [[NSMutableAttributedString alloc] initWithString:nameString];
  84. [attr1 setAttributes:@{NSForegroundColorAttributeName : kAppGrayColor1} range:[nameString rangeOfString:model.to_nick_name]];
  85. self.replyLabel.attributedText = attr1;
  86. CGFloat height = [nameString boundingRectWithSize:CGSizeMake(kScreenW-70, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:11]} context:nil].size.height;
  87. CGFloat nameWidth =[model.to_nick_name sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]}].width;//蓝色名字的宽度
  88. if (height < 20)
  89. {
  90. height = 20;
  91. }
  92. self.replyLabel.frame = CGRectMake(60, CGRectGetMaxY(self.nameLabel.frame), kScreenW-70, height);
  93. self.lineView.frame = CGRectMake(60, CGRectGetMaxY(self.replyLabel.frame)+9, kScreenW-60, 1);
  94. self.clearBtn.frame = CGRectMake(60, 0, kScreenW-60, self.lineView.frame.size.height+self.lineView.frame.origin.y);
  95. if (nameWidth > 0)
  96. {
  97. self.nameBtn.frame = CGRectMake(80, CGRectGetMaxY(self.nameLabel.frame), nameWidth+5, 20);
  98. self.nameBtn.tag = row;
  99. }
  100. return self.lineView.frame.size.height+self.lineView.frame.origin.y;
  101. }
  102. #pragma mark 点击cell
  103. - (void)buttonClick:(UIButton *)btn
  104. {
  105. if (self.CDelegate && [self.CDelegate respondsToSelector:@selector(commentNewsWithTag:)])
  106. {
  107. [self.CDelegate commentNewsWithTag:(int)btn.tag];
  108. }
  109. }
  110. #pragma mark 点击名字
  111. - (void)clickNameString:(UIButton *)btn
  112. {
  113. if (self.CDelegate && [self.CDelegate respondsToSelector:@selector(clickNameStringWithTag:)])
  114. {
  115. [self.CDelegate clickNameStringWithTag:(int)btn.tag];
  116. }
  117. }
  118. #pragma mark 点击头像
  119. - (void)imgViewTap:(UITapGestureRecognizer *)tap
  120. {
  121. if (self.CDelegate && [self.CDelegate respondsToSelector:@selector(clickNameStringWithTag:)])
  122. {
  123. [self.CDelegate clickNameStringWithTag:(int)tap.view.tag];
  124. }
  125. }
  126. @end