Not sure if it is possible, but is there a way to change the status bar color depending on the time? I was fiddling with this code:
import UIKit
class testTimeController: UIViewController{
func lightstatusbar() {
var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
func darkstatusbar() {
var preferredStatusBarStyle: UIStatusBarStyle {
return .default
}
}
override func viewDidLoad() {
super.viewDidLoad()
let hour = NSCalendar.current.component(.hour, from: NSDate() as Date)
switch hour{
case 1..<6: lightstatusbar()
break
case 7..<18: darkstatusbar()
break
case 19..<24: lightstatusbar()
break
default: darkstatusbar()
}
}
The other answers don't work for me, so here is my working solution, regarding to this answer:
Step 1 Add following to your
info.plist
:View controller-based status bar appearance
with Boolean valueNO
Step 2 Add this to
application(_:didFinishLaunchingWithOptions:)
inAppDelegate.swift
: