您的位置:首页 > Web前端 > CSS

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

2015-07-05 16:03 585 查看
【状态栏】

在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];



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: