如何以编程方式将全局色调颜色更改为绿色?

时间:2014-03-13 23:01:58

标签: ios appdelegate tintcolor

我想将全局色调颜色从默认蓝色更改为深绿色,最好是通过向应用代理添加代码,但我尝试过的任何工作都没有。我是xcode的新手,所以如果你能用简单的语言表达你的答案,我将非常感激。

我尝试过添加类似答案的代码,但我不知道该把它放在哪里,是的,我想我要做的是设置关键窗口的色调

@implementation NestopiaAppDelegate {
    UIWindow *window;
    UITabBarController *tabBarController;
    GamesViewController *gamesViewController;
    GamesViewController *savedGamesViewController;
    GamesViewController *favoritesViewController;
    SettingsViewController *settingsViewController;

}

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    [self setupViewControllers];

    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    window.rootViewController = tabBarController;
    [window makeKeyAndVisible];
}

- (void)setupViewControllers {
    gamesViewController = [[GamesViewController alloc] init];
    savedGamesViewController = [[GamesViewController alloc] init];
    savedGamesViewController.saved = YES;

    favoritesViewController = [[GamesViewController alloc] init];
    favoritesViewController.favorite = YES;

    settingsViewController = [[SettingsViewController alloc] init];

    tabBarController = [[UITabBarController alloc] init];
    tabBarController.viewControllers = @[ [self wrapViewController:gamesViewController],
                                         [self wrapViewController:savedGamesViewController],
                                          [self wrapViewController:favoritesViewController],
                                    [[UINavigationController alloc] initWithRootViewController:settingsViewController] ];
}

- (UINavigationController *)wrapViewController:(UIViewController *)viewController {
    // In order to avoid all the mess with contentInset on iOS 7, we just wrap each UIViewController in a navigationBar-less UINavigationController.

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
    navigationController.navigationBarHidden = YES;
    return navigationController;
}

@end

1 个答案:

答案 0 :(得分:0)

您可能希望将UIAppearance代理对象用于此目的。 (https://developer.apple.com/library/ios/documentation/uikit/reference/UIAppearance_Protocol/Reference/Reference.html

例如:

NSDictionary *attributes = @{UITextAttributeTextColor : [UIColor greenColor]};
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];

您必须更改每个控件的颜色。