VLCStatusLabel.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*****************************************************************************
  2. * VLCStatusLabel.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Gleb Pinigin <gpinigin # gmail.com>
  10. *
  11. * Refer to the COPYING file of the official project for license.
  12. *****************************************************************************/
  13. #import "VLCStatusLabel.h"
  14. @interface VLCStatusLabel ()
  15. {
  16. NSTimer *_displayTimer;
  17. }
  18. @end
  19. @implementation VLCStatusLabel
  20. - (void)showStatusMessage:(NSString *)message
  21. {
  22. self.text = message;
  23. /* layout and horizontal center in super view */
  24. [self sizeToFit];
  25. CGRect selfFrame = self.frame;
  26. CGRect parentFrame = [self superview].bounds;
  27. selfFrame.size.width += 15.; // take extra width into account for our custom drawing
  28. selfFrame.origin.x = (parentFrame.size.width - selfFrame.size.width) / 2.;
  29. [self setFrame:selfFrame];
  30. [self setNeedsDisplay];
  31. if (_displayTimer)
  32. [_displayTimer invalidate];
  33. else
  34. [self setHidden:NO animated:YES];
  35. _displayTimer = [NSTimer scheduledTimerWithTimeInterval:1.5
  36. target:self
  37. selector:@selector(_hideAgain)
  38. userInfo:nil
  39. repeats:NO];
  40. }
  41. - (void)_hideAgain
  42. {
  43. [self setHidden:YES animated:YES];
  44. _displayTimer = nil;
  45. }
  46. - (void)setHidden:(BOOL)hidden animated:(BOOL)animated
  47. {
  48. CGFloat alpha = hidden? 0.0f: 1.0f;
  49. if (!hidden) {
  50. self.alpha = 0.0f;
  51. self.hidden = NO;
  52. }
  53. void (^animationBlock)() = ^() {
  54. self.alpha = alpha;
  55. };
  56. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  57. self.hidden = hidden;
  58. };
  59. NSTimeInterval duration = animated? 0.3: 0.0;
  60. [UIView animateWithDuration:duration animations:animationBlock completion:completionBlock];
  61. }
  62. - (void)drawRect:(CGRect)rect
  63. {
  64. self.backgroundColor = [UIColor clearColor];
  65. CGContextClearRect(UIGraphicsGetCurrentContext(), rect);
  66. UIColor *drawingColor = [UIColor VLCDarkBackgroundColor];
  67. [drawingColor setFill];
  68. UIBezierPath* bezierPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:rect.size.height / 2];
  69. [bezierPath fill];
  70. [super drawRect:rect];
  71. }
  72. @end