本文主要是介绍swift3.0 导航栏,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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=navigationCreturn 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. } }
有用的话打个赏吧
这篇关于swift3.0 导航栏的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!