VLCStatusLabel.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // VLCStatusLabel.m
  3. // AspenProject
  4. //
  5. // Created by Felix Paul Kühne on 17.05.13.
  6. // Copyright (c) 2013 VideoLAN. All rights reserved.
  7. //
  8. #import "VLCStatusLabel.h"
  9. @implementation VLCStatusLabel
  10. - (void)showStatusMessage:(NSString *)message
  11. {
  12. self.text = message;
  13. [self setNeedsDisplay];
  14. [self _toggleVisibility:NO];
  15. _displayTimer = [NSTimer scheduledTimerWithTimeInterval:1.5
  16. target:self
  17. selector:@selector(_hideAgain)
  18. userInfo:nil
  19. repeats:NO];
  20. }
  21. - (void)_hideAgain
  22. {
  23. [self _toggleVisibility:YES];
  24. _displayTimer = nil;
  25. }
  26. - (void)_toggleVisibility:(BOOL)hidden
  27. {
  28. CGFloat alpha = hidden? 0.0f: 1.0f;
  29. if (!hidden) {
  30. self.alpha = 0.0f;
  31. self.hidden = NO;
  32. }
  33. void (^animationBlock)() = ^() {
  34. self.alpha = alpha;
  35. };
  36. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  37. self.hidden = hidden;
  38. };
  39. [UIView animateWithDuration:0.3f animations:animationBlock completion:completionBlock];
  40. }
  41. - (void)drawRect:(CGRect)rect
  42. {
  43. self.backgroundColor = [UIColor clearColor];
  44. CGContextClearRect(UIGraphicsGetCurrentContext(), rect);
  45. UIColor *drawingColor = [UIColor colorWithWhite:.20 alpha:.7];
  46. [drawingColor setFill];
  47. UIBezierPath* bezierPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:rect.size.height / 2];
  48. [bezierPath fill];
  49. [super drawRect:rect];
  50. }
  51. @end