VLCDeleteHintTVView.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*****************************************************************************
  2. * VLC for iOS
  3. *****************************************************************************
  4. * Copyright (c) 2015 VideoLAN. All rights reserved.
  5. * $Id$
  6. *
  7. * Authors: Tobias Conradi <videolan # tobias-conradi.de>
  8. *
  9. * Refer to the COPYING file of the official project for license.
  10. *****************************************************************************/
  11. #import "VLCDeleteHintTVView.h"
  12. @implementation VLCDeleteHintTVView
  13. - (instancetype)initWithFrame:(CGRect)frame
  14. {
  15. self = [super initWithFrame:frame];
  16. if (self) {
  17. [self sharedSetup];
  18. }
  19. return self;
  20. }
  21. - (void)awakeFromNib
  22. {
  23. [super awakeFromNib];
  24. [self sharedSetup];
  25. }
  26. - (void)prepareForInterfaceBuilder
  27. {
  28. [super prepareForInterfaceBuilder];
  29. [self sharedSetup];
  30. }
  31. - (void)sharedSetup
  32. {
  33. self.backgroundColor = nil;
  34. /*
  35. * Views
  36. */
  37. UIVisualEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
  38. UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
  39. effectView.frame = self.bounds;
  40. effectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  41. effectView.layer.cornerRadius = 5.0;
  42. effectView.clipsToBounds = YES;
  43. [self addSubview:effectView];
  44. self.effectView = effectView;
  45. UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
  46. UIColor *textColor = [UIColor whiteColor];
  47. UILabel *leadingLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  48. leadingLabel.translatesAutoresizingMaskIntoConstraints = NO;
  49. leadingLabel.font = font;
  50. leadingLabel.textColor = textColor;
  51. [self addSubview:leadingLabel];
  52. self.leadingLabel = leadingLabel;
  53. UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"PlayPauseRemoteButton"]];
  54. imageView.translatesAutoresizingMaskIntoConstraints = NO;
  55. imageView.tintColor = textColor;
  56. [self addSubview:imageView];
  57. self.glyphImageView = imageView;
  58. UILabel *trailingLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  59. trailingLabel.translatesAutoresizingMaskIntoConstraints = NO;
  60. trailingLabel.font = font;
  61. trailingLabel.textColor = textColor;
  62. [self addSubview:trailingLabel];
  63. self.trailingLabel = trailingLabel;
  64. /*
  65. * Content
  66. */
  67. NSString *localizedString = NSLocalizedString(@"DELETE_ITEM_HINT", @"Insert %@ where play-pause-glyph should be placed");
  68. NSArray *strings = [localizedString componentsSeparatedByString:@"%@"];
  69. NSCharacterSet *trimmSet = [NSCharacterSet whitespaceCharacterSet];
  70. leadingLabel.text = [strings.firstObject stringByTrimmingCharactersInSet:trimmSet];
  71. if (strings.count > 1) {
  72. trailingLabel.text = [strings.lastObject stringByTrimmingCharactersInSet:trimmSet];
  73. }
  74. /*
  75. * Constraints
  76. */
  77. NSMutableArray<NSLayoutConstraint*> *constraints = [NSMutableArray array];
  78. // label margins
  79. const CGFloat sideMargin = -60.0;
  80. [constraints addObject:[self.leadingAnchor constraintEqualToAnchor:leadingLabel.leadingAnchor constant:sideMargin]];
  81. [constraints addObject:[trailingLabel.trailingAnchor constraintEqualToAnchor:self.trailingAnchor constant:sideMargin]];
  82. // image margins
  83. const CGFloat imageMargin = -16.0;
  84. [constraints addObject:[leadingLabel.trailingAnchor constraintEqualToAnchor:imageView.leadingAnchor constant:imageMargin]];
  85. [constraints addObject:[imageView.trailingAnchor constraintEqualToAnchor:trailingLabel.leadingAnchor constant:imageMargin]];
  86. [constraints addObject:[self.topAnchor constraintEqualToAnchor:imageView.topAnchor constant:imageMargin]];
  87. [constraints addObject:[self.bottomAnchor constraintEqualToAnchor:imageView.bottomAnchor constant:-imageMargin]];
  88. // vertical alignment
  89. [constraints addObject:[leadingLabel.centerYAnchor constraintEqualToAnchor:imageView.centerYAnchor]];
  90. [constraints addObject:[imageView.centerYAnchor constraintEqualToAnchor:trailingLabel.centerYAnchor]];
  91. [self addConstraints:constraints];
  92. }
  93. @end