1.在AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let sb=UIStoryboard(name: "Main", bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: "asdf")
let navigationC=UINavigationController(rootViewController: vc)
self.window?.rootViewController=navigationC
return true
}
注意
let vc = sb.instantiateViewController(withIdentifier: "asdf")是你将要显示导航栏的页面的StoryboardID
2.ViewController.swift
class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.title="图书信息采集工具" //设置导航栏背景色 self.navigationController?.navigationBar.barTintColor=UIColor.lightGray // //导航栏还可以设置图片. // self.navigationController?.navigationBar.setBackgroundImage(UIImage(named: "testn self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white] let item = UIBarButtonItem(title: "", style: .plain, target: self, action: nil) self.navigationItem.backBarButtonItem = item; } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
有用的话打个赏吧