CommentCell.m 2.9 KB

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