STCell.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #import "STCell.h"
  2. @implementation STCell
  3. - (void)awakeFromNib {
  4. [super awakeFromNib];
  5. // Initialization code
  6. }
  7. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  8. [super setSelected:selected animated:animated];
  9. }
  10. +(STCell*)cellForTableView:(UITableView*)tableView
  11. {
  12. STCell* cell = [tableView dequeueReusableCellWithIdentifier:@"STCell"];
  13. if (!cell) {
  14. cell = [[STCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"STCell"];
  15. [cell.textLabel setTextColor:subTitleColor];
  16. [cell.detailTextLabel setTextColor:contentTextColor];
  17. }
  18. return cell;
  19. }
  20. //消息
  21. -(void)setModel:(NSDictionary *)model
  22. {
  23. _model = model;
  24. NSString *path = model[@"PHOTO"];
  25. if (path && ![path hasPrefix:@"http"]){
  26. path = [imgPreFix stringByAppendingString:path];
  27. }
  28. [self.imageView sd_setImageWithURL: [NSURL URLWithString: path] placeholderImage:randomPortrait()];
  29. [self.textLabel setText:model[@"CONTENT"]];
  30. [self.textLabel setFont:[UIFont scaleSize:18]];
  31. [self.textLabel setNumberOfLines:0];
  32. [self.detailTextLabel setText:model[@"CRDATE"]];
  33. [self.detailTextLabel setTextAlignment:NSTextAlignmentRight];
  34. }
  35. //点赞评论
  36. -(void)setModelReply:(NSDictionary *)model
  37. {
  38. _modelReply = model;
  39. NSString *path = model[@"HEADIMG"];
  40. if (path && ![path hasPrefix:@"http"]){
  41. path = [imgPreFix stringByAppendingString:path];
  42. }
  43. [self.imageView sd_setImageWithURL: [NSURL URLWithString: path] placeholderImage:randomPortrait()];
  44. int type = [model[@"TYPE"] intValue];
  45. if (2 == type) {
  46. [self.textLabel setText:[model[@"NAME"] stringByAppendingString:@"赞了您的话题"] ];
  47. }else if (1 == type){
  48. [self.textLabel setText:[model[@"NAME"] stringByAppendingString:@"回复了您的评论"] ];
  49. }else{
  50. [self.textLabel setText:[model[@"NAME"] stringByAppendingString:@"评论了您的话题"] ];
  51. }
  52. [self.detailTextLabel setText:model[@"CRDATE"]];
  53. }
  54. -(void)layoutSubviews
  55. {
  56. [super layoutSubviews];
  57. CGFloat wid = self.width;
  58. CGFloat hei = self.height;
  59. CGFloat x,y,w,h;
  60. if (_model)
  61. {
  62. x = 27;
  63. y = 15;
  64. w = h = 43;
  65. [self.imageView setFrame:CGRectMake(x, y, w, h)];
  66. self.imageView.layer.masksToBounds = YES;
  67. self.imageView.layer.cornerRadius = self.imageView.height/2.0;
  68. x += w + 10;
  69. y = 10;
  70. w = wid - x - 20;
  71. h = hei - 40;
  72. [self.textLabel setFrame:CGRectMake(x, y, w, h)];
  73. [self.textLabel.layer setMasksToBounds:YES];
  74. x = wid - 180;
  75. w = 160;
  76. y = hei - 30;
  77. h = 21;
  78. [self.detailTextLabel setFrame:CGRectMake(x, y, w, h)];
  79. }
  80. if (_modelReply)
  81. {
  82. x = 30;
  83. y = hei*.2;
  84. w = h = hei - y*2;
  85. [self.imageView setFrame:CGRectMake(x, y, w, h)];
  86. self.imageView.layer.masksToBounds = YES;
  87. self.imageView.layer.cornerRadius = self.imageView.height/2.0;
  88. x += w + 10;
  89. w = wid - x;
  90. h = hei*.3;
  91. [self.textLabel setFrame:CGRectMake(x, y, w, h)];
  92. y = hei* .6;
  93. h = hei*.3;
  94. [self.detailTextLabel setFrame:CGRectMake(x, y, w, h)];
  95. }
  96. }
  97. @end