VLCPlaylistGridViewCell.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // VLCGridViewCell.m
  3. // AspenProject
  4. //
  5. // Created by Felix Paul Kühne on 11.04.13.
  6. // Copyright (c) 2013 VideoLAN. All rights reserved.
  7. //
  8. #import "VLCPlaylistGridViewCell.h"
  9. @interface VLCPlaylistGridViewCell (Hack)
  10. @property (nonatomic, retain) NSString * reuseIdentifier;
  11. @end
  12. @implementation VLCPlaylistGridViewCell
  13. - (void)dealloc
  14. {
  15. [_thumbnailView release];
  16. [_titleLabel release];
  17. [_subtitleLabel release];
  18. [super dealloc];
  19. }
  20. - (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
  21. {
  22. self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier];
  23. if (self == nil)
  24. return nil;
  25. _thumbnailView = [[UIImageView alloc] initWithFrame:CGRectZero];
  26. _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  27. _titleLabel.highlightedTextColor = [UIColor whiteColor];
  28. _titleLabel.textColor = [UIColor colorWithWhite:.95 alpha:1.];
  29. _titleLabel.font = [UIFont boldSystemFontOfSize:12.];
  30. _titleLabel.adjustsFontSizeToFitWidth = YES;
  31. _titleLabel.minimumFontSize = 10.;
  32. _subtitleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  33. _subtitleLabel.highlightedTextColor = [UIColor whiteColor];
  34. _subtitleLabel.textColor = [UIColor colorWithWhite:.95 alpha:1.];
  35. _subtitleLabel.font = [UIFont systemFontOfSize:9.];
  36. _subtitleLabel.adjustsFontSizeToFitWidth = YES;
  37. _subtitleLabel.minimumFontSize = 8.;
  38. self.backgroundColor = [UIColor colorWithWhite:.5 alpha:1.];
  39. self.contentView.backgroundColor = self.backgroundColor;
  40. _thumbnailView.backgroundColor = self.backgroundColor;
  41. _titleLabel.backgroundColor = self.backgroundColor;
  42. _subtitleLabel.backgroundColor = self.backgroundColor;
  43. [self.contentView addSubview:_thumbnailView];
  44. [self.contentView addSubview:_titleLabel];
  45. [self.contentView addSubview:_subtitleLabel];
  46. return self;
  47. }
  48. - (UIImage *)thumbnail
  49. {
  50. return _thumbnailView.image;
  51. }
  52. - (void)setThumbnail:(UIImage *)newThumb
  53. {
  54. _thumbnailView.image = newThumb;
  55. [self setNeedsLayout];
  56. }
  57. - (NSString *)title
  58. {
  59. return _titleLabel.text;
  60. }
  61. - (void)setTitle:(NSString *)newTitle
  62. {
  63. _titleLabel.text = newTitle;
  64. [self setNeedsLayout];
  65. }
  66. - (NSString *)subtitle
  67. {
  68. return @"";
  69. }
  70. - (void)setSubtitle:(NSString *)newSubtitle
  71. {
  72. _subtitleLabel.text = newSubtitle;
  73. [self setNeedsLayout];
  74. }
  75. - (void)layoutSubviews
  76. {
  77. [super layoutSubviews];
  78. CGSize imageSize = _thumbnailView.image.size;
  79. CGRect bounds = CGRectInset(self.contentView.bounds, 10., 10.);
  80. [_titleLabel sizeToFit];
  81. CGRect frame = _titleLabel.frame;
  82. frame.size.width = MIN(frame.size.width, bounds.size.width);
  83. frame.origin.y = CGRectGetMaxY(bounds) - frame.size.height - 15.;
  84. frame.origin.x = floorf((bounds.size.width - frame.size.width) * 0.5);
  85. _titleLabel.frame = frame;
  86. [_subtitleLabel sizeToFit];
  87. frame = _subtitleLabel.frame;
  88. frame.size.width = MIN(frame.size.width, bounds.size.width);
  89. frame.origin.y = CGRectGetMaxY(bounds) - frame.size.height;
  90. frame.origin.x = floorf((bounds.size.width - frame.size.width) * 0.5);
  91. _subtitleLabel.frame = frame;
  92. bounds.size.height = frame.origin.y - bounds.origin.y;
  93. if ((imageSize.width <= bounds.size.width) && (imageSize.height <= bounds.size.height))
  94. return;
  95. CGFloat hRatio = bounds.size.width / imageSize.width;
  96. CGFloat vRatio = bounds.size.height / imageSize.height;
  97. CGFloat ratio = MIN(hRatio, vRatio);
  98. [_thumbnailView sizeToFit];
  99. frame = _thumbnailView.frame;
  100. frame.size.width = floorf(imageSize.width * ratio);
  101. frame.size.height = floorf(imageSize.height * ratio);
  102. frame.origin.x = floorf((bounds.size.width - frame.size.width) * 0.5);
  103. frame.origin.y = floorf((bounds.size.height - frame.size.height) * 0.5);
  104. _thumbnailView.frame = frame;
  105. }
  106. @end