Skip to content

Instantly share code, notes, and snippets.

@kyungpyoda
Created November 11, 2021 01:17
Show Gist options
  • Save kyungpyoda/0b1886999aaf752877b38fd87ad5b990 to your computer and use it in GitHub Desktop.
Save kyungpyoda/0b1886999aaf752877b38fd87ad5b990 to your computer and use it in GitHub Desktop.
[iOS, Swift] Dynamic Status Bar Style with Navigation Controller
//
// DynamicStatusBarNavigation.swift
//
// Created by 홍경표 on 2021/09/09.
//
import UIKit
/// This NavigationController makes embedded viewControllers show their own `preferredStatusBarStyle`
/// , which cannot implemented in default `UINavigationController`.
///
public class DynamicStatusBarNavigation: UINavigationController {
override var childForStatusBarStyle: UIViewController? {
return topViewController
}
}
// Usage
public class AnyWhereYouWant: UIViewController {
public func showSomeViewController() {
let viewController = SomeViewController()
let navi = DynamicStatusBarNavigation(rootViewController: viewController)
// present or whatever
}
}
// In ViewController which embedded in DynamicStatusBarNavigation
public class SomeViewController: UIViewController {
public override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent // Makes statusBar white
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment