//每一個被導(dǎo)航視圖控制器所管理的視圖控制器都有一個navigationItem(這里面包含了左按鈕渔隶,右按鈕,中間標(biāo)題,中間視圖)
//設(shè)置導(dǎo)航欄的標(biāo)題
navigationItem.title="Setting"
letleftBarBtn =UIBarButtonItem(barButtonSystemItem: .Camera, target:self, action:"leftBtnAction")
//設(shè)置右邊按鈕
letrightBarBtn =UIBarButtonItem(title:"next", style:UIBarButtonItemStyle.Plain, target:self, action:"rightBtnAction")
//設(shè)置導(dǎo)航欄左按鈕leftBarButtonItem:(UIBarButtonItem)
navigationItem.leftBarButtonItem= leftBarBtn
navigationItem.rightBarButtonItem= rightBarBtn
//設(shè)置左右item數(shù)組
//navigationItem.leftBarButtonItems = [leftBarBtn,rightBarBtn]
//navigationItem.rightBarButtonItems = [leftBarBtn,rightBarBtn]
//設(shè)置中間視圖
letsegment =UISegmentedControl(items: ["已接來電","未接來dian"])
segment.frame=CGRectMake(0,0,100,30)
segment.selectedSegmentIndex=1
//設(shè)置中間視圖
navigationItem.titleView= segment
//導(dǎo)航欄(UINavigationBar)
//在本類中(視圖控制器)訪問navigationController就是獲取到本視圖控制器所在的導(dǎo)航視圖控制器
//設(shè)置導(dǎo)航欄是否隱藏
navigationController?.navigationBarHidden=false
//設(shè)置導(dǎo)航欄樣式
navigationController?.navigationBar.barStyle= .Default
//背景顏色
navigationController?.navigationBar.backgroundColor=UIColor.cyanColor()
//導(dǎo)航欄本身的顏色
navigationController?.navigationBar.barTintColor=UIColor.yellowColor()
//導(dǎo)航欄元素顏色(左按鈕盛正,右按鈕.........)
navigationController?.navigationBar.tintColor=UIColor.redColor()
//導(dǎo)航欄半透明效果
navigationController?.navigationBar.translucent=false
letmyView =UIView(frame:CGRectMake(0,0,150,150))
myView.backgroundColor=UIColor.blueColor()
view.addSubview(myView)
//navigationController的contentView顯示的誰的View删咱?
}
//跳轉(zhuǎn)第二個控制器頁面
funcrightBtnAction(){
//(1)創(chuàng)建第二個控制器
letsecondVC =SecondViewController()
//(2)使用當(dāng)前控制器所在的導(dǎo)航視圖控制器跳轉(zhuǎn)到第二個控制器pushViewController(進入到下一個頁面)
navigationController?.pushViewController(secondVC, animated:true)
}
funcleftBtnAction(){
print("click left Btn")
}
overridefuncdidReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
overridefuncviewDidLoad() {
super.viewDidLoad()
//設(shè)置頁面顏色為白色
view.backgroundColor=UIColor.whiteColor()
//設(shè)置標(biāo)題
navigationItem.title="SecondVC"
letleftBarBtn =UIBarButtonItem(title:"back", style:UIBarButtonItemStyle.Plain, target:self, action:"backAction:")
navigationItem.leftBarButtonItem= leftBarBtn
letrightBtn =UIBarButtonItem(title:"進入3", style:UIBarButtonItemStyle.Plain, target:self, action:"pushToThirdVC")
navigationItem.rightBarButtonItem= rightBtn
}
funcpushToThirdVC(){
letthirdVC =ThirdViewController()
navigationController?.pushViewController(thirdVC, animated:true)
}
funcbackAction(btn:UIBarButtonItem){
print("返回")
//將SecondVc出棧popViewControllerAnimated:將當(dāng)前顯示在棧頂?shù)目刂破鞒鰲?回到上一個頁面)
navigationController?.popViewControllerAnimated(true)
}
overridefuncdidReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
overridefuncviewDidLoad() {
super.viewDidLoad()
navigationItem.title="thirdVC"
letrightBtn =UIBarButtonItem(title:"進入4", style:UIBarButtonItemStyle.Plain, target:self, action:"pushToFourthVC")
navigationItem.rightBarButtonItem= rightBtn
}
funcpushToFourthVC(){
letfourthVC =FourthViewController()
navigationController?.pushViewController(fourthVC, animated:true)
}
overridefuncdidReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}