VLCStatusLabel.m 2.0 KB

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