iOS-狀態列字型顏色【白色】【Xcode9.1】,ios-xcode9.1
Xcode9之前
設定狀態列顏色首先在info.plist檔案中,加入UIViewControllerBasedStatusBarAppearance = false;
<key>UIViewControllerBasedStatusBarAppearance</key> <false/>
讓後在delegate didFinishLaunchingWithOptions 方法中加入下面的代碼就可以了;
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
Xcode9之後
xcode9.1我在設定狀態列字型為白色時,按照上面的方法行不通,搜羅了一圈有了結果;
同樣在info.plist中,加入 UIViewControllerBasedStatusBarAppearance = true, 注意是true;
<key>UIViewControllerBasedStatusBarAppearance</key><true/>
接著建立一個基於 UINavigationController 的類 BaseNavigationController,一個基於 UIViewController 類 BaseViewController ;
BaseNavigationController.m
-(UIViewController *)childViewControllerForStatusBarStyle { return self.topViewController;}-(UIViewController *)childViewControllerForStatusBarHidden { return self.topViewController;}
BaseViewController.m
-(UIStatusBarStyle)preferredStatusBarStyle{ ///這裡設定白色 return UIStatusBarStyleLightContent;}
-(BOOL)prefersStatusBarHidden{ return NO;}
在項目中如果建立UINavigationController就繼承BaseNavigationController,建立UIViewController就繼承BaseViewController,這樣就可以實現狀態列字型改變了;如果你是已經有的現有項目,可以擴充UINavigationController和UIViewController,來進行實現;