Swift基础(三十一)UINavigationController
2016-07-27 15:36
399 查看
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.mainScreen().bounds)
// 将UINavigationController对象作为视图的根视图
window?.rootViewController = UINavigationController(rootViewController: RootViewController())
window?.makeKeyAndVisible()
return true
}
class RootViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.view.backgroundColor = UIColor.whiteColor()
// UINavigationController
// 设置标题
self.navigationItem.title = "UINavigationController演示"
// 隐藏导航栏
// self.navigationController?.navigationBarHidden = true
// 或者以动画方式隐藏导航栏
// self.navigationController?.setNavigationBarHidden(true, animated: true)
// 设置左选项按钮
self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Cancel, target: self, action: "cancelClick")
// 设置有选项按钮
self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Bookmarks, target: self, action: "bookmarksClick")
// 设置navigationItem的颜色
self.navigationController?.navigationBar.tintColor = UIColor.redColor()
// 设置navigationBar的颜色
self.navigationController?.navigationBar.barTintColor = UIColor.orangeColor()
}
// 左按钮触发事件
func cancelClick() {
self.dismissViewControllerAnimated(true) {
}
}
// 右按钮触发事件
func bookmarksClick() {
var alertView = UIAlertView(title: "欢迎阅读", message: nil, delegate: nil, cancelButtonTitle: "确定")
alertView.show()
}
}
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.mainScreen().bounds)
// 将UINavigationController对象作为视图的根视图
window?.rootViewController = UINavigationController(rootViewController: RootViewController())
window?.makeKeyAndVisible()
return true
}
class RootViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.view.backgroundColor = UIColor.whiteColor()
// UINavigationController
// 设置标题
self.navigationItem.title = "UINavigationController演示"
// 隐藏导航栏
// self.navigationController?.navigationBarHidden = true
// 或者以动画方式隐藏导航栏
// self.navigationController?.setNavigationBarHidden(true, animated: true)
// 设置左选项按钮
self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Cancel, target: self, action: "cancelClick")
// 设置有选项按钮
self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Bookmarks, target: self, action: "bookmarksClick")
// 设置navigationItem的颜色
self.navigationController?.navigationBar.tintColor = UIColor.redColor()
// 设置navigationBar的颜色
self.navigationController?.navigationBar.barTintColor = UIColor.orangeColor()
}
// 左按钮触发事件
func cancelClick() {
self.dismissViewControllerAnimated(true) {
}
}
// 右按钮触发事件
func bookmarksClick() {
var alertView = UIAlertView(title: "欢迎阅读", message: nil, delegate: nil, cancelButtonTitle: "确定")
alertView.show()
}
}
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- Apple Swift学习教程
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- 肯特·贝克:改变人生的代码整理魔法
- 你应该学习哪种编程语言?
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- [转]我们需要一种其他人能使用的编程语言
- 介绍 Fedora 上的 Swift
- DB2编程序技巧(1)
- DB2编程序技巧 (四)
- 女人VS编程_国庆快乐
- DB2编程序技巧 (六)
- DB2编程序技巧 (三)
- DB2编程序技巧 (九)
- DB2编程序技巧 (七)