2
0

AirplayActiveView.m 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright (C) 2012 IGN Entertainment, Inc. */
  2. #import "AirplayActiveView.h"
  3. #import <QuartzCore/QuartzCore.h>
  4. #import "WFCUImage.h"
  5. @interface AirplayActiveView ()
  6. @property (readwrite, strong) CAGradientLayer *gradientLayer;
  7. @property (readwrite, strong) UIImageView *displayImageView;
  8. @property (readwrite, strong) UILabel *titleLabel;
  9. @property (readwrite, strong) UILabel *descriptionLabel;
  10. @end
  11. @implementation AirplayActiveView
  12. - (id)initWithFrame:(CGRect)frame
  13. {
  14. if ((self = [super initWithFrame:frame])) {
  15. _gradientLayer = [[CAGradientLayer alloc] init];
  16. [_gradientLayer setColors:@[
  17. (id)[[UIColor colorWithWhite:0.22f alpha:1.0f] CGColor],
  18. (id)[[UIColor colorWithWhite:0.09f alpha:1.0f] CGColor],
  19. ]];
  20. [_gradientLayer setLocations:@[ @0.0, @1.0 ]];
  21. [[self layer] addSublayer:_gradientLayer];
  22. _displayImageView = [[UIImageView alloc] initWithImage:[WFCUImage imageNamed:@"airplay-display.png"]];
  23. [self addSubview:_displayImageView];
  24. _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  25. [_titleLabel setText:@"Airplay"];
  26. [_titleLabel setFont:[UIFont fontWithName:@"DINRoundCompPro" size:20.0f]];
  27. [_titleLabel setTextColor:[UIColor colorWithWhite:0.5f alpha:1.0f]];
  28. [_titleLabel setBackgroundColor:[UIColor clearColor]];
  29. [self addSubview:_titleLabel];
  30. _descriptionLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  31. [_descriptionLabel setText:@"This video is playing elsewhere"];
  32. [_descriptionLabel setFont:[UIFont fontWithName:@"DINRoundCompPro" size:14.0f]];
  33. [_descriptionLabel setTextColor:[UIColor colorWithWhite:0.36f alpha:1.0f]];
  34. [_descriptionLabel setBackgroundColor:[UIColor clearColor]];
  35. [self addSubview:_descriptionLabel];
  36. }
  37. return self;
  38. }
  39. - (void)layoutSubviews
  40. {
  41. [super layoutSubviews];
  42. CGRect bounds = [self bounds];
  43. [_gradientLayer setFrame:bounds];
  44. CGSize displayImageSize = [[_displayImageView image] size];
  45. if (bounds.size.height < 300) {
  46. displayImageSize = CGSizeMake(displayImageSize.width / 2, displayImageSize.height / 2);
  47. }
  48. CGSize titleLabelSize;
  49. CGSize descriptionLabelSize;
  50. if (@available(iOS 7.0, *)) {
  51. titleLabelSize = [[_titleLabel text] sizeWithAttributes:@{NSFontAttributeName:[_titleLabel font]}];
  52. descriptionLabelSize = [[_descriptionLabel text] sizeWithAttributes:@{NSFontAttributeName:[_descriptionLabel font]}];
  53. } else {
  54. titleLabelSize = [[_titleLabel text] sizeWithFont:[_titleLabel font]];
  55. descriptionLabelSize = [[_descriptionLabel text] sizeWithFont:[_descriptionLabel font]];
  56. }
  57. CGFloat contentHeight = displayImageSize.height + titleLabelSize.height + descriptionLabelSize.height;
  58. CGFloat y = (bounds.size.height / 2) - (contentHeight / 2);
  59. [_displayImageView setFrame:CGRectMake((bounds.size.width / 2) - (displayImageSize.width / 2),
  60. y,
  61. displayImageSize.width,
  62. displayImageSize.height)];
  63. y += displayImageSize.height;
  64. [_titleLabel setFrame:CGRectMake((bounds.size.width / 2) - (titleLabelSize.width / 2),
  65. y,
  66. titleLabelSize.width,
  67. titleLabelSize.height)];
  68. y += titleLabelSize.height - 8;
  69. [_descriptionLabel setFrame:CGRectMake((bounds.size.width / 2) - (descriptionLabelSize.width / 2),
  70. y,
  71. descriptionLabelSize.width,
  72. descriptionLabelSize.height)];
  73. }
  74. @end