UINavigationContoller(rootViewController: ViewController())



我不能得到像在屏幕截图的结果。在这里输入图像描述下面是我在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()
}
}

遗憾的是我不能得到预期的结果。在这里输入图像描述请帮助我了解在SceneDelegate中使用unavcontroller制作应用程序的结构。我正在学习仅通过编程制作应用程序,而没有StoryBoardXcode版本为15.0

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()
}

基础navigationController是

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
}
}
}

相关内容

  • 没有找到相关文章

最新更新