TASCell.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #import "TASCell.h"
  2. @implementation TASCell
  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. // Configure the view for the selected state
  10. }
  11. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  12. {
  13. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  14. if (self) {
  15. UILabel* label;
  16. label = [UILabel new];
  17. [self addSubview:label];
  18. titState = label;
  19. label = [UILabel new];
  20. [self addSubview:label];
  21. lblState = label;
  22. [self.textLabel setFont:[UIFont scaleSize:Font18]];
  23. [self.detailTextLabel setFont:[UIFont scaleSize:Font18]];
  24. [lblState setFont:[UIFont scaleSize:Font18]];
  25. [titState setFont:[UIFont scaleSize:Font18]];
  26. [self.textLabel setTextColor:contentTextColor];
  27. [self.detailTextLabel setTextColor:contentTextColor];
  28. [lblState setTextColor:contentTextColor];
  29. [titState setTextColor:contentTextColor];
  30. }
  31. return self;
  32. }
  33. +(id)cellForTabelView:(UITableView *)tableView
  34. {
  35. id cell = [tableView dequeueReusableCellWithIdentifier:@"TASCell"];
  36. if (!cell) {
  37. cell = [[TASCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TASCell"];
  38. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  39. }
  40. return cell;
  41. }
  42. -(void)setModel:(NSDictionary*)obj andSubject:(NSInteger)sub
  43. {
  44. if (!obj) {
  45. return;
  46. }
  47. subject = sub;
  48. NSArray* arr = @[@"001.png",@"TASimg1.png",@"TASimg2.png",@"TASimg3.png"];
  49. [self.imageView imageName:arr[sub]];
  50. NSString* min,*scroe,*state;
  51. if (1 == sub) {
  52. min = obj[@"oneTime"];
  53. scroe = obj[@"oneScore"];
  54. state = obj[@"oneStatus"];
  55. }
  56. if (2 == sub) {
  57. min = obj[@"twoTime"];
  58. scroe = obj[@"twoScore"];
  59. state = obj[@"twoStatus"];
  60. }
  61. if (3 == sub) {
  62. min = obj[@"threeTime"];
  63. scroe = obj[@"threeScore"];
  64. state = obj[@"threeStatus"];
  65. }
  66. if (!scroe || [scroe isEqualToString:@""]) {
  67. scroe = @"暂无";
  68. }
  69. [self.textLabel setText:[@"完成学时:" stringByAppendingString:min.hourAndmm]];
  70. [self.detailTextLabel setText:[@"科目成绩:" stringByAppendingString:scroe]];
  71. [titState setText:@"科目状态:"];
  72. [lblState setText:state];
  73. if ([state isEqualToString:@"通过"]) {
  74. [lblState setTextColor:defGreen];
  75. }else{
  76. [lblState setTextColor:contentTextColor];
  77. }
  78. }
  79. -(void)layoutSubviews
  80. {
  81. [super layoutSubviews];
  82. CGFloat wid = self.width;
  83. CGFloat hei = self.height;
  84. CGFloat x,y,w,h;
  85. x = 20;
  86. w = h = hei*.5;
  87. y = hei*.25;
  88. [self.imageView setFrame:CGRectMake(x, y, w, h)];
  89. x +=w + 10;
  90. w = wid - x;
  91. h = hei*.5;
  92. y = 0;
  93. [self.textLabel setFrame:CGRectMake(x, y, w, h)];
  94. h = hei;
  95. [self.detailTextLabel setFrame:CGRectMake(x, y, w, h)];
  96. h = y = hei*.5;
  97. [titState setFrame:CGRectMake(x, y, w, h)];
  98. titState.width = [titState.text sizeForFont:Font18].width;
  99. x += titState.width;
  100. [lblState setFrame:CGRectMake(x, y, w, h)];
  101. }
  102. @end
  103. //废弃
  104. CGFloat TASCellHeight()
  105. {
  106. return 150;
  107. }