1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import UIKit
- class NCMainNavigationController: UINavigationController {
-
- required init?(coder: NSCoder) {
- super.init(coder: coder)
- NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil)
- changeTheming()
- }
- override func viewDidLayoutSubviews() {
- super.viewDidLayoutSubviews()
- }
- override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
- super.traitCollectionDidChange(previousTraitCollection)
- changeTheming()
- }
-
- @objc func changeTheming() {
- if #available(iOS 13.0, *) {
- let appearance = UINavigationBarAppearance()
- appearance.configureWithOpaqueBackground()
- appearance.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: NCBrandColor.shared.label]
- appearance.backgroundColor = NCBrandColor.shared.systemBackground
- appearance.configureWithOpaqueBackground()
- appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: NCBrandColor.shared.label]
- appearance.backgroundColor = NCBrandColor.shared.systemBackground
- navigationBar.scrollEdgeAppearance = appearance
- navigationBar.standardAppearance = appearance
- } else {
- navigationBar.barStyle = .default
- navigationBar.barTintColor = NCBrandColor.shared.systemBackground
- navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: NCBrandColor.shared.label]
- navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: NCBrandColor.shared.label]
- }
- navigationBar.tintColor = .systemBlue
- navigationBar.setNeedsLayout()
- }
- }
|