1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- /*****************************************************************************
- * VLCStatusLabel.m
- * VLC for iOS
- *****************************************************************************
- * Copyright (c) 2013 VideoLAN. All rights reserved.
- * $Id$
- *
- * Authors: Felix Paul Kühne <fkuehne # videolan.org>
- * Gleb Pinigin <gpinigin # gmail.com>
- *
- * Refer to the COPYING file of the official project for license.
- *****************************************************************************/
- #import "VLCStatusLabel.h"
- @interface VLCStatusLabel ()
- {
- NSTimer *_displayTimer;
- }
- @end
- @implementation VLCStatusLabel
- - (void)showStatusMessage:(NSString *)message
- {
- self.text = message;
- /* layout and horizontal center in super view */
- [self sizeToFit];
- CGRect selfFrame = self.frame;
- CGRect parentFrame = [self superview].bounds;
- selfFrame.size.width += 15.; // take extra width into account for our custom drawing
- selfFrame.origin.x = (parentFrame.size.width - selfFrame.size.width) / 2.;
- [self setFrame:selfFrame];
- [self setNeedsDisplay];
- if (_displayTimer)
- [_displayTimer invalidate];
- else
- [self setHidden:NO animated:YES];
- _displayTimer = [NSTimer scheduledTimerWithTimeInterval:1.5
- target:self
- selector:@selector(_hideAgain)
- userInfo:nil
- repeats:NO];
- }
- - (void)_hideAgain
- {
- [self setHidden:YES animated:YES];
- _displayTimer = nil;
- }
- - (void)setHidden:(BOOL)hidden animated:(BOOL)animated
- {
- CGFloat alpha = hidden? 0.0f: 1.0f;
- if (!hidden) {
- self.alpha = 0.0f;
- self.hidden = NO;
- }
- void (^animationBlock)() = ^() {
- self.alpha = alpha;
- };
- void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
- self.hidden = hidden;
- };
- NSTimeInterval duration = animated? 0.3: 0.0;
- [UIView animateWithDuration:duration animations:animationBlock completion:completionBlock];
- }
- - (void)drawRect:(CGRect)rect
- {
- self.backgroundColor = [UIColor clearColor];
- CGContextClearRect(UIGraphicsGetCurrentContext(), rect);
- UIColor *drawingColor = [UIColor VLCDarkBackgroundColor];
- [drawingColor setFill];
- UIBezierPath* bezierPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:rect.size.height / 2];
- [bezierPath fill];
- [super drawRect:rect];
- }
- @end
|