I can't get a result like in the screenshoot. enter image description here Here is an example of my code inside of SceneDelegate
SceneDelegate
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(frame: windowScene.coordinateSpace.bounds)
window?.windowScene = windowScene
window?.rootViewController = UINavigationController(rootViewController: ViewController())
window?.makeKeyAndVisible()
}
}
Unfortunately I can't get the expected result. enter image description here Please help me to understand the structure of making app with UiNavController inside SceneDelegate. I'm learning to make the apps only programmatically without StoryBoard Version of Xcode is 15.0
CodePudding user response:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let scene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: scene)
window?.overrideUserInterfaceStyle = .light // for light mode supported only
window?.rootViewController = BaseNavigationController(rootViewController: ViewController())
window?.makeKeyAndVisible()
}
the base navigationController is
import UIKit
class BaseNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 15.0, *) {
let navigationBarAppearance = UINavigationBarAppearance()
navigationBarAppearance.configureWithDefaultBackground()
navigationBarAppearance.backgroundImage = UIImage(named: "NavBarBg") // if wanna add bg image
navigationBarAppearance.backgroundColor = .white // white bar color
UINavigationBar.appearance().standardAppearance = navigationBarAppearance
UINavigationBar.appearance().compactAppearance = navigationBarAppearance
UINavigationBar.appearance().scrollEdgeAppearance = navigationBarAppearance
navigationBar.tintColor = .white
navigationBar.isTranslucent = false
}
}
}