Compatible UINavigationBarAppearance for all iOS versions
- Provide AdvancedNavigationBar is able to change size
- Easy to apply navigation bar style for all iOS versions
- Apply navigation bar style as one interface for all iOS versions
- Provide compatible UINavigationBarAppearance for versions below iOS 13
- Provide CompatibleNavigationBarAppearance like UINavigationBarAppearance that is available on iOS 13 higher
- Automatically apply appearance to navigation bar through the view controller life cycle
let navigationController = UINavigationController(
rootViewController: #{YourVC},
navigationBarClass: PageSheetNavigationBar.self)
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UINavigationBarDecorator.isAllowsSwizzleLifeCycleOfViewController = true
UINavigationBarDecorator.factory = SampleNavigationBarDecoratorFactory()
return true
}
}
struct SampleNavigationBarDecoratorFactory: UINavigationBarDecoratorFactory {
func create(of vc: UIViewController) -> UINavigationBarDecorator? {
switch vc {
case is RootViewController:
return .init(standard: .orange, compact: .orange, scrollEdge: .orange)
case is SecondViewController:
return .init(standard: .purple, compact: .purple, scrollEdge: .purple)
default:
return nil
}
}
}
extension CompatibleNavigationBarAppearance {
static var purple: CompatibleNavigationBarAppearance {
let appearance = CompatibleNavigationBarAppearance()
appearance.backgroundColor = .purple
appearance.tintColor = .white
appearance.largeTitleTextAttributes = [
.foregroundColor: UIColor.white
]
appearance.titleTextAttributes = [
.foregroundColor: UIColor.white,
.font : UIFont.systemFont(ofSize: 17, weight: .semibold)
]
return appearance
}
static var orange: CompatibleNavigationBarAppearance {
let appearance = CompatibleNavigationBarAppearance()
appearance.backgroundColor = .orange
appearance.tintColor = .black
appearance.largeTitleTextAttributes = [
.foregroundColor: UIColor.black
]
appearance.titleTextAttributes = [
.foregroundColor: UIColor.black,
.font : UIFont.systemFont(ofSize: 17, weight: .semibold)
]
return appearance
}
}
- set the decorator directly on the view controller
final class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationBarDecorator = .init(standard: .orange, compact: .orange, scrollEdge: .orange)
}
}
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UINavigationBarDecorator.isAllowsSwizzleLifeCycleOfViewController = false
UINavigationBarDecorator.factory = SampleNavigationBarDecoratorFactory()
return true
}
}
final class SampleNavigationController: UINavigationController {
override var childForStatusBarStyle: UIViewController? {
topViewController
}
override func viewDidLoad() {
super.viewDidLoad()
delegate = self
}
}
extension SampleNavigationController: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
viewController.navigationBarDecorator?.decorate(to: viewController)
}
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
viewController.navigationBarDecorator?.decorate(to: viewController, by: viewController.view.frame.size)
}
}
To run the example project, clone the repo, and run pod install
from the Example directory first.
iOS SDK 9.0 equal or higher
UINavigationBarDecorator is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "UINavigationBarDecorator"
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate Alamofire into your Xcode project using Carthage, specify it in your Cartfile
:
github "pisces/UINavigationBarDecorator" ~> 1.0.8
Run carthage update
to build the framework and drag the built UINavigationBarDecorator.framework
into your Xcode project.
Steve Kim, hh963103@gmail.com
UINavigationBarDecorator is available under the BSD license. See the LICENSE file for more info.