您的位置:首页 > 移动开发 > Swift

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()

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息