我無法得到螢屏截圖中的結果。在此處輸入影像描述 這是我在 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 中使用 UiNavController 制作應用程式的結構。我正在學習在沒有 StoryBoard的情況下僅以編程方式制作應用程式 Xcode 版本為 15.0
uj5u.com熱心網友回復:
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()
}
基本的導航控制器是
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
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/490875.html
上一篇:可變寬度StackView?
