狀態列文字顏色變更

1 篇文章 / 0 new
author
狀態列文字顏色變更
►文字顏色
1. info.plist 設置 UIViewControllerBasedStatusBarAppearance  = false
2. 程式中使用
UIApplication.shared.statusBarStyle = UIStatusBarStyle.default;
或是
UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent; //白色文字

► 狀態列控制
// AppDelegate.swift 全部隱藏
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    application.isStatusBarHidden = true;
    return true;
}
或是 View 內加入 UIApplication.shared.setStatusBarHidden(true, with: UIStatusBarAnimation.none) 則僅該View 隱藏.

► 背景顏色
let statusBarWindow : UIView = UIApplication.shared.value(forKey: "statusBarWindow") as! UIView;
let statusBar : UIView = statusBarWindow.value(forKey: "statusBar") as! UIView;
if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
    statusBar.backgroundColor = color;
}
Free Web Hosting