UIBarButtonItem+Theme.m 3.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//
//  UIBarButtonItem+Theme.m
//  VLC for iOS
//
//  Created by Romain Goyet on 14/06/13.
//  Copyright (c) 2013 Applidium. All rights reserved.
//
//  Refer to the COPYING file of the official project for license.
//

#import "UIBarButtonItem+Theme.h"

@implementation UIBarButtonItem (Theme)
+ (UIBarButtonItem *)themedDoneButtonWithTarget:(id)target andSelector:(SEL)selector
{
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_DONE", @"")
                                                                      style:UIBarButtonItemStyleBordered
                                                                     target:target
                                                                     action:selector];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
20
    if (SYSTEM_RUNS_IOS7_OR_LATER)
21 22 23 24 25 26 27 28
        doneButton.tintColor = [UIColor whiteColor];
    else {
        [doneButton setBackgroundImage:[UIImage imageNamed:@"doneButton"]
                              forState:UIControlStateNormal
                            barMetrics:UIBarMetricsDefault];
        [doneButton setBackgroundImage:[UIImage imageNamed:@"doneButtonHighlight"]
                              forState:UIControlStateHighlighted
                            barMetrics:UIBarMetricsDefault];
29 30
        [doneButton setTitleTextAttributes:@{UITextAttributeTextShadowColor : [UIColor whiteColor], UITextAttributeTextColor : [UIColor blackColor]}
                                  forState:UIControlStateNormal];
31
    }
32 33
    return doneButton;
}
34 35 36 37 38 39 40

+ (UIBarButtonItem *)themedBackButtonWithTarget:(id)target andSelector:(SEL)selector
{
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_BACK", @"")
                                                                   style:UIBarButtonItemStyleBordered
                                                                  target:target
                                                                  action:selector];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
41
    if (SYSTEM_RUNS_IOS7_OR_LATER)
42 43 44 45 46 47 48 49 50
        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];
    }
51
    [backButton setTitleTextAttributes:@{UITextAttributeTextShadowColor : [UIColor colorWithWhite:0. alpha:.37], UITextAttributeTextColor : [UIColor whiteColor]} forState:UIControlStateNormal];
Fabio Ritrovato's avatar
Fabio Ritrovato committed
52
    [backButton setTitlePositionAdjustment:UIOffsetMake(3, 0) forBarMetrics:UIBarMetricsDefault];
53 54 55
    return backButton;
}

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

68 69 70
    return menuButton;
}

71
@end