VLCStatusLabel.m 2.3 KB

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