目錄:[Swift]Xcode實際操做html
本文將演示對導航欄進行樣式設置,以及更改導航頂部的提示區。ide
選擇編輯第一個視圖控制器文件。post
1 import UIKit 2 3 class FirstSubViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 8 // Do any additional setup after loading the view. 9 self.title = "First Page" 10 self.view.backgroundColor = UIColor.brown 11 self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Next", style: UIBarButtonItem.Style.plain, target: self, action: #selector(FirstSubViewController.nextPage)) 12 } 13 14 @objc func nextPage() 15 { 16 let viewController = SecondSubViewController() 17 self.navigationController?.pushViewController(viewController, animated: true) 18 } 19 20 //創建視圖控制器對象的生命週期中的,視圖即將顯示的代理方法。 21 //視圖在即將顯示時,,執行這個方法 22 override func viewWillAppear(_ animated: Bool) { 23 //首先實現父類的同名方法 24 super.viewWillAppear(animated) 25 //設置頂部導航區的提示文字 26 self.navigationItem.prompt = "Loading..." 27 //設置導航欄的背景是否透明 28 self.navigationController?.navigationBar.isTranslucent = false 29 //設置導航欄的系統樣式 30 self.navigationController?.navigationBar.barStyle = UIBarStyle.black 31 //設置導航欄的前景顏色。 32 self.navigationController?.navigationBar.tintColor = UIColor.orange 33 } 34 35 override func didReceiveMemoryWarning() { 36 super.didReceiveMemoryWarning() 37 // Dispose of any resources that can be recreated. 38 } 39 }