UIBarButtonItem+Theme.m 4.12 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * UIBarButtonItem+Theme.m
 * VLC for iOS
 *****************************************************************************
5
 * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
6 7 8 9 10 11 12
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne # videolan.org>
 *          Fabio Ritrovato <sephiroth87 # videolan.org>
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/
13

14
@implementation UIBarButtonItem (ThemedButtons)
15 16 17

+ (UIBarButtonItem *)themedBackButtonWithTarget:(id)target andSelector:(SEL)selector
{
18
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_BACK", nil)
19 20 21
                                                                   style:UIBarButtonItemStyleBordered
                                                                  target:target
                                                                  action:selector];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
22
    if (SYSTEM_RUNS_IOS7_OR_LATER)
23 24 25 26 27 28 29 30 31
        backButton.tintColor = [UIColor whiteColor];
    else {
        [backButton setBackgroundImage:[[UIImage imageNamed:@"backButton"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12, 0, 6)]
                              forState:UIControlStateNormal
                            barMetrics:UIBarMetricsDefault];
        [backButton setBackgroundImage:[[UIImage imageNamed:@"backButtonHighlight"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12, 0, 6)]
                              forState:UIControlStateHighlighted
                            barMetrics:UIBarMetricsDefault];
    }
32
    [backButton setTitleTextAttributes:@{UITextAttributeTextShadowColor : [UIColor colorWithWhite:0. alpha:.37], UITextAttributeTextColor : [UIColor whiteColor]} forState:UIControlStateNormal];
Fabio Ritrovato's avatar
Fabio Ritrovato committed
33
    [backButton setTitlePositionAdjustment:UIOffsetMake(3, 0) forBarMetrics:UIBarMetricsDefault];
34 35 36
    return backButton;
}

37 38
+ (UIBarButtonItem *)themedRevealMenuButtonWithTarget:(id)target andSelector:(SEL)selector
{
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
    /* After day 354 of the year, the usual VLC cone is replaced by another cone
     * wearing a Father Xmas hat.
     * Note: this icon doesn't represent an endorsement of The Coca-Cola Company
     * and should not be confused with the idea of religious statements or propagation there off
     */
    NSCalendar *gregorian =
    [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:[NSDate date]];
    UIImage *icon;
    if (dayOfYear >= 354)
        icon = [UIImage imageNamed:@"vlc-xmas"];
    else
        icon = [UIImage imageNamed:@"menuCone"];

    UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStyleBordered target:target action:selector];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
54
    if (SYSTEM_RUNS_IOS7_OR_LATER)
55 56 57 58 59
        menuButton.tintColor = [UIColor whiteColor];
    else {
        [menuButton setBackgroundImage:[UIImage imageNamed:@"button"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        [menuButton setBackgroundImage:[UIImage imageNamed:@"buttonHighlight"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
    }
60
    menuButton.accessibilityLabel = NSLocalizedString(@"OPEN_VLC_MENU", nil);
61 62
    menuButton.isAccessibilityElement = YES;

63 64 65
    return menuButton;
}

66 67 68 69 70 71 72 73 74 75 76 77
+ (UIBarButtonItem *)themedDarkToolbarButtonWithTitle:(NSString*)title target:(id)target andSelector:(SEL)selector
{
    UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStyleBordered target:target action:selector];
    if (SYSTEM_RUNS_IOS7_OR_LATER)
        button.tintColor = [UIColor whiteColor];
    else {
        [button setBackgroundImage:[[UIImage imageNamed:@"darkButton"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        [button setBackgroundImage:[[UIImage imageNamed:@"darkButtonHighlight"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    }

    return button;
}
78
@end