CommentCell.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // CommentCell.m
  3. // jiaPeiC
  4. //
  5. // Created by apple on 16/3/21.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "CommentCell.h"
  9. #import "UIImageView+WebCache.h"
  10. @implementation CommentCell
  11. - (void)awakeFromNib {
  12. [super awakeFromNib];
  13. // Initialization code
  14. }
  15. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  16. {
  17. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  18. if (self) {
  19. UIImageView* iv = [[UIImageView alloc] init];
  20. iv.layer.masksToBounds = YES;
  21. iv.contentMode = UIViewContentModeCenter;
  22. [iv setContentMode:UIViewContentModeScaleAspectFit];
  23. [iv boardWid:1.5 Color:defGreen];
  24. [self.contentView addSubview:iv];
  25. headImg = iv;
  26. UILabel* lb;
  27. lb = [[UILabel alloc] init];
  28. [lb setTextColor:titleColor];
  29. [lb setFont:[UIFont scaleSize:Font16]];
  30. [self.contentView addSubview:lb];
  31. nameLabel = lb;
  32. lb = [[UILabel alloc] init];
  33. [lb setTextColor:contentTextColor];
  34. [lb setFont:[UIFont scaleSize:Font14]];
  35. lb.numberOfLines = 0;
  36. [self.contentView addSubview:lb];
  37. contentLabel = lb;
  38. lb = [[UILabel alloc] init];
  39. [lb setTextColor:contentTextColor];
  40. [lb setFont:[UIFont scaleSize:Font14]];
  41. [self.contentView addSubview:lb];
  42. dateLabel = lb;
  43. }
  44. [self setSelectionStyle:UITableViewCellSelectionStyleNone];
  45. return self;
  46. }
  47. -(void)setDict:(NSDictionary *)dict
  48. {
  49. _dict = dict;
  50. NSString *path = dict[@"HEADIMG"];
  51. if (!path) {
  52. path = @"";
  53. }
  54. [headImg sd_setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:[NSString stringWithFormat:@"portrait%d.png",arc4random()%10 + 1]]];
  55. [nameLabel setText:dict[@"NAME"]];
  56. [contentLabel setText:dict[@"PJCONTENT"]];
  57. NSString* str = dict[@"PJSJ"];
  58. if (str && str.length >11) {
  59. [dateLabel setText:[str substringToIndex:11]];
  60. }else{
  61. [dateLabel setText:str];
  62. }
  63. }
  64. -(void)layoutSubviews
  65. {
  66. [super layoutSubviews];
  67. CGFloat aWid = self.width;
  68. CGFloat x,w,h,y,bd;
  69. x = 8;
  70. w = h = 62;
  71. y = bd = 10;
  72. [headImg setFrame:CGRectMake(x, y, w, h)];
  73. headImg.layer.cornerRadius = h/2.0;
  74. y += bd;
  75. x += w + bd;
  76. h = 25;
  77. [nameLabel setFrame:CGRectMake(x, y, 200, h)];
  78. y = y+h;
  79. h = 25;
  80. [dateLabel setFrame:CGRectMake(x, y, 200, h)];
  81. y += h + bd;
  82. w = aWid - x - bd;
  83. h = [contentLabel.text heightForWid:w Font:Font14];
  84. if (h < 30.0)
  85. {
  86. h = 30;
  87. }
  88. [contentLabel setFrame:CGRectMake(x, y, w, h)];
  89. //固定高度90 最小高度120
  90. }
  91. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  92. [super setSelected:selected animated:animated];
  93. // Configure the view for the selected state
  94. }
  95. @end