이전에는 동일한 문제가 있었지만이를 해결하기 위해 프로그래밍 방식으로 탐색 모음을 만들었습니다. 이를 위해 함수를 생성하고 함수를 viewDidLoad
또는 viewDidAppear
에서 호출 할 수 있습니다.
func addNavBar() {
let navigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height:54)) // Offset by 20 pixels vertically to take the status bar into account
navigationBar.barTintColor = UIColor.black
navigationBar.tintColor = UIColor.white
navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white]
// Create a navigation item with a title
let navigationItem = UINavigationItem()
navigationItem.title = "NavBarAppears!"
// Create left and right button for navigation item
let leftButton = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(btn_clicked(_:)))
let rightButton = UIBarButtonItem(title: "Right", style: .plain, target: self, action: nil)
// Create two buttons for the navigation item
navigationItem.leftBarButtonItem = leftButton
navigationItem.rightBarButtonItem = rightButton
// Assign the navigation item to the navigation bar
navigationBar.items = [navigationItem]
// Make the navigation bar a subview of the current view controller
self.view.addSubview(navigationBar)
}
func btn_clicked(_ sender: UIBarButtonItem) {
// Do something
performSegue(withIdentifier: "segueBackToHomeVC", sender: self)
}