iOS开发常见问题

iOS-隐藏状态栏

2016-08-25  本文已影响83人  亦晴工作室

IOS9:

在需要隐藏状态栏的ViewController里面添加下面的方法

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

改变状态栏的样式

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

typedef NS_ENUM(NSInteger, UIStatusBarStyle) {
    UIStatusBarStyleDefault                                     = 0, // Dark content, for use on light backgrounds
    UIStatusBarStyleLightContent     NS_ENUM_AVAILABLE_IOS(7_0) = 1, // Light content, for use on dark backgrounds
    
    UIStatusBarStyleBlackTranslucent NS_ENUM_DEPRECATED_IOS(2_0, 7_0, "Use UIStatusBarStyleLightContent") = 1,
    UIStatusBarStyleBlackOpaque      NS_ENUM_DEPRECATED_IOS(2_0, 7_0, "Use UIStatusBarStyleLightContent") = 2,
};

IOS9以前:
隐藏状态栏:

plist 文件里面:
Localization native development region改为 NO
Status bar style 改为 Opaque black style

//隐藏状态栏
     [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:YES];
     //重新设定窗口的显示区域
     [[UIApplication sharedApplication].keyWindow setFrame:CGRectMake(0, 0, 320, 480)];
     //重新设定标题栏显示的位置
     [self.navigationController.navigationBar setFrame:CGRectMake(0, 0, 320, 44)];

改变状态栏的样式:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
上一篇下一篇

猜你喜欢

热点阅读