

隨著 iOS 7 的到來,在隱藏 Status Bar 上也有一些不同的做法,下面就分成從 UIStoryboard、UIViewController 檔案 和 info.plist 檔案三方面來介紹。
UIStoryboard
在從 UIStoryboard 中設定隱藏該 UIViewController 的 Status Bar 上,與之前的方法不同,在左手邊選擇你的 UIViewController 物件,並且在右手邊的 Attributes Inspector 的標籤頁中找到 Status Bar 設定成 None。
![]() |
在 Attributes Inspector 標籤頁中將 Status Bar 設定成 None。 |
UIViewController 檔案
iOS 6 SDK 以前的版本
你可以使用 [UIApplication sharedApplication] 來取得目前應用程式的 Instance,進而隱藏 Status Bar。
UIApplication *app = [UIApplication sharedApplication];
[app setStatusBarHidden:YES withAnimation:YES];
iOS 7 SDK
改寫 SDK 中的 prefersStatusBarHidden 函式,並回傳 YES 值。
- (BOOL)prefersStatusBarHidden
{
return YES;
}
//在某些情況下你可以會需要強制重新繪製 Status Bar
[self setNeedsStatusBarAppearanceUpdate];
Info.plist 檔案
iOS 6 SDK 以前的版本
在 Info.plist 中新增 Status bar is initially hidden 欄位,並設定值為 YES。(如下圖)
iOS 7 SDK
除了設定 Status bar is initially hidden 的數值外,並需另外新增 View controller-based status bar appearance 欄位,並設定值為 NO。
![]() |
從 Info.plist 中設定移除 Status bar |
沒有留言:
張貼留言