https://developer.apple.com/documentation/uikit/uinavigationcontroller
UINavigationController | Apple Developer Documentation
A container view controller that defines a stack-based scheme for navigating hierarchical content.
developer.apple.com
https://developer.apple.com/documentation/uikit/uinavigationbar
UINavigationBar | Apple Developer Documentation
Navigational controls that display in a bar along the top of the screen, usually in conjunction with a navigation controller.
developer.apple.com
네비게이션 바를 코드로 구현
SceneDelegate.swift 파일에서 scene 함수에 아래 코드 작성
"UINavigationController" 인스턴스 생성
NaiviAndTab 폴더 내에 SecondViewController.swift 파일 생성
ViewController.swift 파일에 네비게이션 바 관련된 함수 구현
네비게이션 버튼을 눌렀을 때 동작할 함수 (didTapSecond) 구현 및
viewdidload 함수 설정
ViewController 전체 코드
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemYellow
configureNavigationBar()
}
@objc func didTapSecond() {
let SecondVC = SecondViewController()
navigationController?.pushViewController(SecondVC, animated: true)
}
private func configureNavigationBar() {
let appearance = UINavigationBarAppearance()
// appearance.configureWithOpaqueBackground() // 불투명으로
// appearance.backgroundColor = .brown // 색상설정
// appearance.configureWithTransparentBackground() // 투명으로
navigationController?.navigationBar.tintColor = .blue
navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.compactAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = appearance
title = "Main"
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Add", style: .plain, target: self, action: #selector(didTapSecond))
}
}
'UIKIT' 카테고리의 다른 글
iOS 화면 표현 구조 (1) | 2024.01.22 |
---|---|
테이블 만들기 (0) | 2024.01.21 |
BMI 계산기 (화면 전환 및 데이터 전달) (0) | 2024.01.16 |
화면 이동과 데이터 전달 1편 (0) | 2024.01.14 |
ViewController의 라이프 사이클 (1) | 2024.01.10 |