更改所有场景的导航栏颜色

时间:2015-09-18 16:56:03

标签: ios uinavigationbar

我是Objective-c的新手,我需要在所有场景中更改导航栏颜色。据我所知,这句话应该这样做:

UINavigationBar.Appearance.barTintColor = UIColor.Black;
UINavigationBar.Appearance.TintColor = UIColor.White;

但我不知道在哪里设置它们。

2 个答案:

答案 0 :(得分:0)

应在application:didFinishLaunchingWithOptions:中调用外观代理,即之前任何界面都有可能被创建。

答案 1 :(得分:0)

    UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
    [navigationBarAppearance setBarTintColor:[UIColor ybnMediumGrayColor]];
    [navigationBarAppearance setTitleTextAttributes:@{NSFontAttributeName: [UIFont ybnProximaNovaSemiboldFontWithSize:22.0],
                                                  NSForegroundColorAttributeName: [UIColor whiteColor]}];

    UIBarButtonItem *barButtonItemAppearance = [UIBarButtonItem appearance];
    [barButtonItemAppearance setTitleTextAttributes:@{NSFontAttributeName: [UIFont ybnProximaNovaSemiboldFontWithSize:19.0]} forState:UIControlStateNormal];

尝试类似上面的代码。这对我有用。