FMSongListTableViewCell.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // FMSongListTableViewCell.m
  3. // FreeMusic
  4. //
  5. //
  6. #import "FMSongListTableViewCell.h"
  7. #import "UIView+Additions.h"
  8. #import "FMSongListModel.h"
  9. @implementation FMSongListTableViewCell
  10. -(NSString*)TimeformatFromSeconds:(int)seconds
  11. {
  12. int totalm = seconds/(60);
  13. int h = totalm/(60);
  14. int m = totalm%(60);
  15. int s = seconds%(60);
  16. if (h==0) {
  17. return [[NSString stringWithFormat:@"%02d:%02d", m, s] substringToIndex:5];
  18. }
  19. return [NSString stringWithFormat:@"%02d:%02d:%02d", h, m, s];
  20. }
  21. -(void)setModel:(FMSongListModel *)model_
  22. {
  23. _model = model_;
  24. nameLabel.text = _model.title;
  25. timeLabel.text =[self TimeformatFromSeconds:_model.file_duration];
  26. titleLabel.text = [NSString stringWithFormat:@"%@•%@",_model.author,_model.album_title];
  27. }
  28. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  29. {
  30. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  31. if (self) {
  32. self.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
  33. // Initialization code
  34. nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 5, self.contentView.size.width-16-60, 25)];
  35. nameLabel.font = [UIFont systemFontOfSize:16.0f];
  36. // nameLabel.backgroundColor = [UIColor redColor];
  37. [self.contentView addSubview:nameLabel];
  38. timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(nameLabel.size.width+nameLabel.origin.x, nameLabel.size.height/2+nameLabel.origin.y, 40, 25)];
  39. timeLabel.font = [UIFont systemFontOfSize:14.0f];
  40. // timeLabel.backgroundColor = [UIColor blueColor];
  41. timeLabel.textColor = [UIColor lightGrayColor];
  42. [self.contentView addSubview:timeLabel];
  43. titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(nameLabel.origin.x, nameLabel.size.height+nameLabel.origin.y, nameLabel.size.width, 25)];
  44. titleLabel.font = [UIFont systemFontOfSize:14.0f];
  45. // titleLabel.backgroundColor = [UIColor greenColor];
  46. titleLabel.textColor = [UIColor lightGrayColor];
  47. [self.contentView addSubview:titleLabel];
  48. }
  49. return self;
  50. }
  51. /*
  52. // Only override drawRect: if you perform custom drawing.
  53. // An empty implementation adversely affects performance during animation.
  54. - (void)drawRect:(CGRect)rect
  55. {
  56. // Drawing code
  57. }
  58. */
  59. @end