VLCStatusLabel.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. @implementation VLCStatusLabel
  15. - (void)showStatusMessage:(NSString *)message
  16. {
  17. self.text = message;
  18. /* layout and horizontal center in super view */
  19. [self sizeToFit];
  20. CGRect selfFrame = self.frame;
  21. CGRect parentFrame = [self superview].bounds;
  22. selfFrame.size.width += 15.; // take extra width into account for our custom drawing
  23. selfFrame.origin.x = (parentFrame.size.width - selfFrame.size.width) / 2.;
  24. [self setFrame:selfFrame];
  25. [self setNeedsDisplay];
  26. if (_displayTimer)
  27. [_displayTimer invalidate];
  28. else
  29. [self _toggleVisibility:NO];
  30. _displayTimer = [NSTimer scheduledTimerWithTimeInterval:1.5
  31. target:self
  32. selector:@selector(_hideAgain)
  33. userInfo:nil
  34. repeats:NO];
  35. }
  36. - (void)_hideAgain
  37. {
  38. [self _toggleVisibility:YES];
  39. _displayTimer = nil;
  40. }
  41. - (void)_toggleVisibility:(BOOL)hidden
  42. {
  43. CGFloat alpha = hidden? 0.0f: 1.0f;
  44. if (!hidden) {
  45. self.alpha = 0.0f;
  46. self.hidden = NO;
  47. }
  48. void (^animationBlock)() = ^() {
  49. self.alpha = alpha;
  50. };
  51. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  52. self.hidden = hidden;
  53. };
  54. [UIView animateWithDuration:0.3f animations:animationBlock completion:completionBlock];
  55. }
  56. - (void)drawRect:(CGRect)rect
  57. {
  58. self.backgroundColor = [UIColor clearColor];
  59. CGContextClearRect(UIGraphicsGetCurrentContext(), rect);
  60. UIColor *drawingColor = [UIColor colorWithWhite:.20 alpha:.7];
  61. [drawingColor setFill];
  62. UIBezierPath* bezierPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:rect.size.height / 2];
  63. [bezierPath fill];
  64. [super drawRect:rect];
  65. }
  66. @end