Status bar的顯示和隱藏
- 如果想要的效果是啟動(dòng)時(shí)隱藏断凶,進(jìn)入軟件之后顯示
- 可以在設(shè)置中勾選
Hide status bar
選項(xiàng)
-
View controller-based status bar appearance
- NO - 代表status bar 的控制權(quán)限給了UIApplication
- YES(默認(rèn)值) - 代表控制器的優(yōu)先級(jí)比UIApplication高悦陋,而且這個(gè)時(shí)候使用UIApplication控制status bar 將沒(méi)有效果
最簡(jiǎn)單的方法(我自己認(rèn)為)
- 在info.plist中配置
View controller-based status bar appearance
為NO
- 全部頁(yè)面都隱藏
- 在
AppDelegate
的application:didFinishLaunchingWithOptions:
方法中設(shè)置
[UIApplication sharedApplication].statusBarHidden = YES;
- 有的頁(yè)面需要隱藏
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[UIApplication sharedApplication].statusBarHidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[UIApplication sharedApplication].statusBarHidden = NO;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}
控制器自己控制狀態(tài)欄
- 當(dāng)info.plist中沒(méi)有對(duì)
View controller-based status bar appearance
設(shè)置,默認(rèn)值是YES
/**
讓當(dāng)前控制器對(duì)應(yīng)的狀態(tài)欄改變顏色,是白色還是黑色
*/
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
/**
讓當(dāng)前控制器對(duì)應(yīng)的狀態(tài)欄顯示或者隱藏
*/
- (BOOL)prefersStatusBarHidden
{
return YES;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者