補(bǔ)充筆記01-導(dǎo)航欄的設(shè)置與處理

導(dǎo)航欄的設(shè)置與處理

*首先創(chuàng)建一個(gè)視圖,并創(chuàng)建好導(dǎo)航欄管理控件

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
       //創(chuàng)建一個(gè)窗口
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        //使窗口可見
        self.window?.makeKeyAndVisible()
        //關(guān)聯(lián)ViewController
        let viewCrt = ViewController()
        //創(chuàng)建導(dǎo)航欄管理器
        let navCrt = UINavigationController(rootViewController: viewCrt)
        self.window?.rootViewController = navCrt
        //設(shè)置導(dǎo)航欄顏色
        navCrt.navigationBar.barTintColor = UIColor.redColor()
        //設(shè)置導(dǎo)航欄上所有添加上去的視圖顏色(包括label和button/image)
        navCrt.navigationBar.tintColor = UIColor.blackColor()
        return true
    }

*然后進(jìn)行添加導(dǎo)航欄上的東西

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor.whiteColor()
        
        //創(chuàng)建一個(gè)系統(tǒng)button
        let button = UIButton(type: .System)
        button.frame = CGRect(x: self.view.frame.size.width / 2 - 50, y: self.view.frame.size.height / 2 - 25, width: 100, height: 50)
        
        button.tintColor = UIColor.redColor()
        button.setTitle("first page", forState: .Normal)
        button.addTarget(self, action: #selector(didClick(_:)), forControlEvents: .TouchUpInside)
        self.view.addSubview(button)
        
        //設(shè)置導(dǎo)航欄上的中間title內(nèi)容,默認(rèn)為居中
        self.navigationItem.title = "首頁(yè)"
        
        //設(shè)置系統(tǒng)的圖標(biāo)擺放至導(dǎo)航欄左側(cè)
//        self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Edit, target: self, action: #selector(didClick(_:)))
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", style: .Done, target: self, action: nil)
        
        //設(shè)置導(dǎo)航欄右側(cè)內(nèi)容,添加一個(gè)button,點(diǎn)擊觸發(fā)事件為didClick
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "下一頁(yè)", style: .Plain, target: self, action: #selector(didClick(_:)))
    }
    
    func didClick(sender: UIButton){
        let seconde = secondeViewController()
        //以棧的形式將第二個(gè)頁(yè)面彈出(push)
        self.navigationController?.pushViewController(seconde, animated: true)
    }
    deinit {
        print("first")
    }
}

*觸發(fā)點(diǎn)擊事件,創(chuàng)建第二個(gè)頁(yè)面,第二個(gè)頁(yè)面的代碼如下:

import UIKit

class secondeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.greenColor()
    }
    //設(shè)置默認(rèn)的返回點(diǎn)擊頁(yè)面(以棧的方式將之前的頁(yè)面返回,pop)
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        self.navigationController?.popViewControllerAnimated(true)
    }
    
    deinit {
        print("second")
    }
    
}


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫(kù)、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,029評(píng)論 4 61
  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,725評(píng)論 25 709
  • 墨竹染就了潔白畫卷,于筆韻下悠然婉轉(zhuǎn),醉影闌珊,你傾城的笑臉,回眸想念…… 客吹洞簫,空曠怡然,孤獨(dú)流轉(zhuǎn)間瞥見你神...
    臺(tái)詞先生閱讀 429評(píng)論 0 1
  • 你相信自我暗示可以代替鬧鐘么? 我以前不信,但是今天,信了。 就在今晚,曼聯(lián)會(huì)在23:30迎來(lái)本賽季的第一場(chǎng)足總杯...
    內(nèi)寒閱讀 968評(píng)論 1 1
  • 霜降已過(guò)十幾天,按常理大麗花該敗才對(duì),但它依然妖媚撩人。 大柱聞到一股香水味,原來(lái)村里最浪的美女春玲站在河對(duì)岸,上...
    黃梅枝閱讀 399評(píng)論 3 8

友情鏈接更多精彩內(nèi)容