VLCStatusLabel.m 1.92 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//
//  VLCStatusLabel.m
//  AspenProject
//
//  Created by Felix Paul Kühne on 17.05.13.
//  Copyright (c) 2013 VideoLAN. All rights reserved.
//

#import "VLCStatusLabel.h"

@implementation VLCStatusLabel

- (void)showStatusMessage:(NSString *)message
{
    self.text = message;
16
17
18
19
20
21
22
23
24

    /* layout and horizontal center in super view */
    [self sizeToFit];
    CGRect selfFrame = self.frame;
    CGRect parentFrame = [self window].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];

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    [self setNeedsDisplay];
    [self _toggleVisibility:NO];

    _displayTimer = [NSTimer scheduledTimerWithTimeInterval:1.5
                                                     target:self
                                                   selector:@selector(_hideAgain)
                                                   userInfo:nil
                                                    repeats:NO];
}

- (void)_hideAgain
{
    [self _toggleVisibility:YES];
    _displayTimer = nil;
}

- (void)_toggleVisibility:(BOOL)hidden
{
    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;
    };

    [UIView animateWithDuration:0.3f animations:animationBlock completion:completionBlock];
}

- (void)drawRect:(CGRect)rect
{
    self.backgroundColor = [UIColor clearColor];
    CGContextClearRect(UIGraphicsGetCurrentContext(), rect);

    UIColor *drawingColor = [UIColor colorWithWhite:.20 alpha:.7];
    [drawingColor setFill];

    UIBezierPath* bezierPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:rect.size.height / 2];
    [bezierPath fill];

    [super drawRect:rect];
}

@end