VLCStatusLabel.m 1.9 KB

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