본문 바로가기
PROGRAMMING CODE/SWIFT

[UIkit] Navigation Bar (코드)

by daye_ 2023. 12. 12.

 

 

네비게이션바 코드 설정

 

 

SceneDelegate.swift

 
 func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let windowScene = (scene as? UIWindowScene) else { return }
        
        window = UIWindow(windowScene: windowScene)
        
        let naviVC = UINavigationController(rootViewController: ViewController())
        
        window?.rootViewController = naviVC
        window?.makeKeyAndVisible()
    }

 

 

ViewController.swift

func setupNaviBar() {
        title = "메모장"
        
        // 네비게이션바 설정관련
        let appearance = UINavigationBarAppearance()
        appearance.configureWithOpaqueBackground()  // 불투명
        appearance.backgroundColor = .white
        navigationController?.navigationBar.tintColor = .systemBlue
        navigationController?.navigationBar.standardAppearance = appearance
        navigationController?.navigationBar.compactAppearance = appearance
        navigationController?.navigationBar.scrollEdgeAppearance = appearance
        
        // 네비게이션 아이템(오른쪽)
        self.navigationItem.rightBarButtonItem = self.plusButton
}