以编程方式呈现 VC

Present VC programmatically

如何在 UINavigationController 中显示 UIViewController() ?我的控制器未全屏显示。 我希望我的应用看起来像这样 enter image description here, but it is end up like this enter image description here

我在没有故事板的情况下制作应用程序(以编程方式)

let customVC = UIViewController()
customVC.view.backgroundColor = .green
customVC.modalPresentationStyle = .fullScreen

let navVC = UINavigationController(rootViewController: customVC)
self.present(navVC, animated: true, completion: nil)
   let customVC = DestinationController()

   let navVC = UINavigationController(rootViewController: customVC)
   // this line overFullScreen
   navVC.modalPresentationStyle = .overFullScreen
// for more style 
   navVC.modalTransitionStyle = .crossDissolve
   self.present(navVC, animated: true, completion: nil)

你的class你想去或去的地方

class DestinationController:UIViewController {
   override func viewDidLoad() {
        super.viewDidLoad() 
        view.backgroundColor = .red
   }
}