VLCStatusLabel.m 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. [self _toggleVisibility:NO];
  27. if (_displayTimer)
  28. [_displayTimer invalidate];
  29. _displayTimer = [NSTimer scheduledTimerWithTimeInterval:1.5
  30. target:self
  31. selector:@selector(_hideAgain)
  32. userInfo:nil
  33. repeats:NO];
  34. }
  35. - (void)_hideAgain
  36. {
  37. [self _toggleVisibility:YES];
  38. _displayTimer = nil;
  39. }
  40. - (void)_toggleVisibility:(BOOL)hidden
  41. {
  42. CGFloat alpha = hidden? 0.0f: 1.0f;
  43. if (!hidden) {
  44. self.alpha = 0.0f;
  45. self.hidden = NO;
  46. }
  47. void (^animationBlock)() = ^() {
  48. self.alpha = alpha;
  49. };
  50. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  51. self.hidden = hidden;
  52. };
  53. [UIView animateWithDuration:0.3f animations:animationBlock completion:completionBlock];
  54. }
  55. - (void)drawRect:(CGRect)rect
  56. {
  57. self.backgroundColor = [UIColor clearColor];
  58. CGContextClearRect(UIGraphicsGetCurrentContext(), rect);
  59. UIColor *drawingColor = [UIColor colorWithWhite:.20 alpha:.7];
  60. [drawingColor setFill];
  61. UIBezierPath* bezierPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:rect.size.height / 2];
  62. [bezierPath fill];
  63. [super drawRect:rect];
  64. }
  65. @end