(七十)Xcode5及以上对于状态栏和导航栏样式的设定方法

【状态栏】

在Xcode5以前,状态栏是通过UIApplication单例来管理的,而在此后,默认情况下状态栏通过控制器来管理,而且如果控制器有NavigationController,那么设置状态栏的操作在NavigationController中进行,调用的方法为:

- (UIStatusBarStyle)preferredStatusBarStyle;

如果要让状态栏仍然通过单例设定,可以在info.plist中加入一个键值:

View controller-based status bar appearance,值为NO即可。

这样就可以通过UIApplication单例来设置状态栏了:

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;


【导航栏】

导航栏的主题属于全局设定,通过UINavigationBar的appearance拿到NavigationBar,再设置样式:

    UINavigationBar *navBar = [UINavigationBar appearance];
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:16];
    [navBar setTitleTextAttributes:attrs];







原文地址:https://www.cnblogs.com/aiwz/p/6154147.html