AppDelegate
//1. 創(chuàng)建窗口
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
//2. 顯示窗口
self.window?.makeKeyAndVisible()
let viewCtrl = ViewController()
/ self.window?.rootViewController = viewCtrl
//3. 創(chuàng)建導(dǎo)航控制器,至少需要放入一個(gè)頁(yè)面(第一個(gè)頁(yè)面也叫做根視圖控制器)
let navCtrl = UINavigationController(rootViewController: viewCtrl)
//文字//圖片
navCtrl.navigationBar.tintColor = UIColor.redColor()
//整個(gè)導(dǎo)航條的顏色
navCtrl.navigationBar.barTintColor = UIColor.greenColor()
self.window?.rootViewController = navCtrl
ViewController
self.view.backgroundColor = UIColor.redColor()
/
self.title = "第一頁(yè)"
用于設(shè)置導(dǎo)航條
/ self.navigationItem.title = "第一頁(yè)"
//設(shè)置導(dǎo)航條中間部分
let v = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 10)) v.backgroundColor = UIColor.blueColor()
self.navigationItem.titleView = v
//設(shè)置左側(cè)
// self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "左側(cè)", style: .Plain, target: self, action: #selector(leftClicked))
// self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Bookmarks, target: self, action: #selector(leftClicked)) let originImage = UIImage(named: "1.png")
//圖片總是顯示原始顏色
let image = originImage?.imageWithRenderingMode(.AlwaysOriginal) self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: image, style: .Plain, target: self, action: #selector(leftClicked))
let btn = UIButton(type: .System)
btn.frame = CGRect(x: self.view.frame.size.width / 2 - 75, y: self.view.frame.size.height / 2 - 25, width: 150, height: 50) btn.setTitle("下一頁(yè)", forState: .Normal)
btn.addTarget(self, action: #selector(didClicked(_:)), forControlEvents: .TouchUpInside) self.view.addSubview(btn)
}
func leftClicked() {
print("leftClicked")
}
func didClicked(sender: UIButton)
{ let secondCtrl = SecondViewController()
//每一個(gè)“已經(jīng)”處于導(dǎo)航控制器中的頁(yè)面,它的navigationController屬性不為空
self.navigationController?.pushViewController(secondCtrl, animated: true)
}
最后編輯于 :
?著作權(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ù)。