我有一个应用程序,其中包含带有三个页面的标签栏控制器,其中我的标签栏控制器是初始视图控制器。我需要为我的三个页面创建一个自定义通用视图作为导航栏。我不需要从头开始创建导航栏。
答案 0 :(得分:0)
首先使用navigationController创建一个类 导入UIKit
class CustomNavigationController: UIViewController {
override func viewDidLoad() {
super .viewDidLoad()
addNavigationButton()
}
func addNavigationButton() {
// here you add custom nevigation
let backButton = UIBarButtonItem(image: UIImage(named: "back"), style: .plain, target: self, action: #selector(backButtonAction))
backButton.tintColor = .gray
self.navigationItem.leftBarButtonItems = [backButton]
let doneButton = UIBarButtonItem(title:"Done", style: .plain, target: self, action: #selector(doneButtonAction))
navigationItem.rightBarButtonItem = doneButton
//navigationItem.rightBarButtonItem = editButtonItem
// self.title = "Select Timezone"
UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor : #colorLiteral(red: 0, green: 0.4156862745, blue: 0.5529411765, alpha: 1)]
}
@objc func backButtonAction() {
// as per requrement you want to use pop / dismisss
self.dismiss(animated: true, completion: nil)
}
@objc func doneButtonAction() {
// as per requrement you want to use pop / dismisss
self.dismiss(animated: true, completion: nil)
}
}
并像这样使用这三个viewcontroller
import UIKit
class ViewController: CustomNavigationController {
override func viewDidLoad() {
super.viewDidLoad()
}
}