RankCell.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // RankCell.m
  3. // jiaPei
  4. //
  5. // Created by apple on 15/11/28.
  6. // Copyright (c) 2015年 JCZ. All rights reserved.
  7. //
  8. #import "RankCell.h"
  9. #import "UIImageView+WebCache.h"
  10. @implementation RankCell
  11. {
  12. UIImageView* honorIv;
  13. UILabel* indLbl;
  14. UILabel* scoLbl;
  15. UIImageView* headIv;
  16. }
  17. - (void)awakeFromNib {
  18. [super awakeFromNib];
  19. // Initialization code
  20. }
  21. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  22. [super setSelected:selected animated:animated];
  23. }
  24. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  25. {
  26. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  27. if (self)
  28. {
  29. indLbl = [[UILabel alloc] init];
  30. [self.contentView addSubview:indLbl];
  31. scoLbl = [[UILabel alloc] init];
  32. [self setAccessoryView:scoLbl];
  33. honorIv = [[UIImageView alloc] init];
  34. [self.contentView addSubview:honorIv];
  35. [honorIv setContentMode:UIViewContentModeScaleAspectFit];
  36. [indLbl setTextAlignment:NSTextAlignmentRight];
  37. headIv = [[UIImageView alloc] init];
  38. [indLbl setTextColor:contentTextColor];
  39. [self.textLabel setTextColor:kTitleColor];
  40. [self.detailTextLabel setTextColor:contentTextColor];
  41. [scoLbl setTextColor:[UIColor redColor]];
  42. }
  43. return self;
  44. }
  45. -(void)setModel:(NSDictionary *)model
  46. {
  47. //NSString *nickName = model[@""];
  48. //如果不通过 只能添加这个字段试试了
  49. [self.textLabel setText:model[@"EI_USERNAME"]];
  50. int num = [model[@"EI_TOTAL_TIME"] intValue];
  51. NSString* str = [NSString stringWithFormat:@"用时%d分%d秒",num/60,num%60];
  52. [self.detailTextLabel setText:str];
  53. str = [NSString stringWithFormat:@"%@分",model[@"EI_SCORE"]];
  54. [scoLbl setText:str];
  55. NSString *urlStr = model[@"USER_PHOTO"];
  56. if (urlStr && urlStr.length > 0) {
  57. [headIv sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"rankDefault"]];
  58. }
  59. }
  60. -(void)setIndex:(NSInteger)index
  61. {
  62. switch (index) {
  63. case 0:
  64. [honorIv setHidden:NO];
  65. [indLbl setHidden:YES];
  66. [honorIv setImage:[UIImage imageNamed:@"rank_first.png"]];
  67. // [headIv setColor:[UIColor redColor]];
  68. [self setBackgroundColor:RGB_COLOR(254, 236, 235)];
  69. break;
  70. case 1:
  71. [honorIv setHidden:NO];
  72. [indLbl setHidden:YES];
  73. // [headIv setColor:[UIColor orangeColor]];
  74. [honorIv setImage:[UIImage imageNamed:@"rank_second.png"]];
  75. [self setBackgroundColor:RGB_COLOR(254, 247, 232)];
  76. break;
  77. case 2:
  78. [honorIv setHidden:NO];
  79. [indLbl setHidden:YES];
  80. // [headIv setColor:defGreen];
  81. [honorIv setImage:[UIImage imageNamed:@"rank_third.png"]];
  82. [self setBackgroundColor:RGB_COLOR(239, 251, 232)];
  83. break;
  84. default:
  85. [indLbl setHidden:NO];
  86. [honorIv setHidden:YES];
  87. // [headIv setColor:nil];
  88. [self setBackgroundColor:[UIColor clearColor]];
  89. break;
  90. }
  91. [headIv setNeedsDisplay];
  92. [indLbl setText:[NSString stringWithFormat:@"%d",(int)index+1]];
  93. }
  94. -(void)layoutSubviews
  95. {
  96. [super layoutSubviews];
  97. CGFloat x,y,w,h,bd;
  98. w = 30;
  99. h = self.height;
  100. x = 20;
  101. y=0;
  102. [honorIv setFrame:CGRectMake(x, y, w, h)];
  103. [indLbl setFrame:CGRectMake(0, y, w+x, h)];
  104. bd = 10;
  105. x += w+15;
  106. y = bd;
  107. h = self.height - y;
  108. w = h;
  109. [headIv setFrame:CGRectMake(x, y, w, h)];
  110. headIv.layer.masksToBounds = YES;
  111. headIv.layer.cornerRadius = h/2;
  112. [self.contentView addSubview:headIv];
  113. x += w + 15;
  114. y = 0;
  115. w = self.width - x;
  116. h = self.height *.6;
  117. [self.textLabel setFrame:CGRectMake(x, y, w, h)];
  118. y = self.height * .4 + 4;
  119. h -= 8;
  120. [self.detailTextLabel setFrame:CGRectMake(x, y, w, h)];
  121. w = self.height;
  122. [scoLbl setFrame:CGRectMake(kSize.width-w, 5, w, w-5)];
  123. }
  124. +(CGFloat)cellHeight
  125. {
  126. return 60;
  127. }
  128. @end