iOS 앱 프로그래밍

[iOS Dev]Apply UINavigationController - Programmatically

후추멍멍이 2021. 11. 26. 16:02
iOS App Development Study - How to apply UINavigationController in Code 
iOS 어플 개발 공부 - 코드로 UINavigationController 적용하기 
  • 개발 환경 : MacBook Pro (13-inch, M1, 2020), Monterey
  • XCode : Version 13.1 (13A1030d), Swift5
  • 시뮬레이터 : iPhone 11

SceneDelegate 내 func scene() 코드 수정

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
		// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
		// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
		// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
		guard let windowScene = (scene as? UIWindowScene) else { return }
		window?.windowScene = windowScene
		window?.makeKeyAndVisible()
		let controller = ViewController()
		let navigationController = UINavigationController(rootViewController: controller)
		window?.rootViewController = navigationController
	}

ViewController 내 코드 작성

override func viewDidLoad() {
		super.viewDidLoad()
        
		// declare backgroundColor, default is black
		view.backgroundColor = .white
		
        ...
        
        // declare the top title
        navigationItem.title = "Title"
        
        // LargeTitle set is true
		navigationController?.navigationBar.prefersLargeTitles = false
        
        ...
	}