Reputation: 4760
Despite there are similar questions, I haven't been able to find a working solution for my situation.
I am working on an app that does all the UI programatically. In my AppDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
setupNavigationBarStyle()
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = UINavigationController(rootViewController: HeadlinesViewController(networkHelper: NetworkHelper.shared))
return true
}
func setupNavigationBarStyle() {
UIApplication.shared.statusBarView!.backgroundColor = UIColor.statusBarBackground
UINavigationBar.appearance().barTintColor = UIColor.navigationBarBackground
UINavigationBar.appearance().tintColor = UIColor.navigationBarTint
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.navigationBarText]
UINavigationBar.appearance().isTranslucent = false
UITabBar.appearance().barTintColor = UIColor.navigationBarBackground
UITabBar.appearance().tintColor = UIColor.navigationBarTint
}
When I am in HeadlinesViewController, I want to show a LoaderOverlayView that covers the whole screen including status bar but it stills shows it as an overlaid view.
The class LoaderOverlayView looks like:
public class LoaderOverlay{
var overlayView = UIView()
var activityIndicator = UIActivityIndicatorView()
var window:UIWindow{
return UIApplication.shared.keyWindow!
}
class var shared: LoaderOverlay {
struct Static {
static let instance:LoaderOverlay = LoaderOverlay()
}
return Static.instance
}
public func showOverlay() {
//¿¿¿???
window.windowLevel = UIWindow.Level.statusBar
overlayView = UIView(frame: UIScreen.main.bounds)
overlayView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5)
activityIndicator = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.whiteLarge)
activityIndicator.center = overlayView.center
overlayView.addSubview(activityIndicator)
activityIndicator.startAnimating()
window.addSubview(overlayView)
}
public func hideOverlayView() {
activityIndicator.stopAnimating()
overlayView.removeFromSuperview()
window.windowLevel = UIWindow.Level.normal
}
}
By changing the windowLevel, the view is showing but the status bar text is missing. Any suggestion?
EDIT
It seems that the problem is when i set the 'statusBarView' background color in 'setupNavigationBarStyle' function which comes from:
extension UIApplication {
var statusBarView: UIView? {
return value(forKey: "statusBar") as? UIView
}
}
Upvotes: 0
Views: 32
Reputation: 4760
I finally realised that
UINavigationBar.appearance().barTintColor = UIColor.navigationBarBackground
was the one giving problems. Once removed, the status bar still gets the same background colour than the navigationBar and it doesn't affect when I show the overlay view.
Upvotes: 1