苹果终于发布了iOS 7正式版,大批的用户都已经纷纷进行了升级。如果App是由Xcode 4.6或者更早版本生成,iOS 7系统会使用兼容模式运行该App,以便尽可能保持原有外观。但是,当使用Xcode 5重新编译App源代码时,此时会使用iOS 7 SDK来进行编译链接。(注意在使用Xcode 5打开旧项目之前备份项目源代码,因为Xcode 5会升级项目中的资源文件,且无法再使用旧版本的Xcode打开。)由于iOS 7 SDK较早期版本的SDK改动较大,因此App的界面也会出现种种问题,其中最明显的问题就是状态栏与导航栏的显示问题。
iOS 6:
iOS7:
当未使用导航栏时,上面的截图对比了在iOS 6与iOS 7上的显示情况。iOS 6中的状态栏不透明,视图控制器的主视图原点在状态栏下面。而iOS 7的状态栏背景色变为透明色,视图控制器的主视图原点在屏幕左上角,即状态栏显示在主视图之上,透过状态栏可以显示视图的内容。
iOS 7提供了两种状态栏的样式,用于控制状态栏文字的颜色。
如果状态栏背景为浅色,应选用黑色字样式(UIStatusBarStyleLightContent);如果背景为深色,则选用白色字样式(UIStatusBarStyleDefault,默认值)。
iOS 7的UIViewController类里添加了几个新的方法,用于控制状态栏。
preferredStatusBarStyle方法用于指定当前视图控制器的状态栏样式,prefersStatusBarHidden方法指定是否隐藏状态栏。当修改了状态栏的字体颜色、显示或隐藏时,调用setNeedsStatusBarAppearanceUpdate方法告知系统需要刷新状态栏。
转载:http://blog.csdn.net/pucker/article/details/12112105
I had the same problem, and figured out it was happening because I wasn't setting the root view controller in my application window.
The UIViewController
in which I had implemented the preferredStatusBarStyle
was used in aUITabBarController
, which controlled the appearance of the views on the screen.
When I set the root view controller to point to this UITabBarController
, the status bar changes started to work correctly, as expected (and the preferredStatusBarStyle
method was getting called).
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
... // other view controller loading/setup code
self.window.rootViewController = rootTabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Alternatively, you can call one of the following methods, as appropriate, in each of your view controllers, depending on its background color, instead of having to use setNeedsStatusBarAppearanceUpdate
:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
or
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
Note that you'll also need to set UIViewControllerBasedStatusBarAppearance
to NO
in the plist file if you use this method.
iOS7 StatusBar 在需要隐藏或改变样式时在UIViewConroller中调用:
[self setNeedsStatusBarAppearanceUpdate];
1、隐藏
StatusBar在iOS7中无法使用一下接口隐藏:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
- (BOOL)prefersStatusBarHidden { return YES; }
2、样式改变
iOS 7中statusbar 有两种样式:白色字体UIStatusBarStyleLightContent和黑色字体UIStatusBarStyleDefault。
如果改变需要在UIViewController中实现:
- (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleDefault; }转载:http://ilost.cc/?p=2521