Xcode9学习笔记21

来源:互联网 发布:android 网络测速代码 编辑:程序博客网 时间:2024/05/24 06:09

        let leftBar = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.refresh, target: self, action: #selector(FirstSubViewController.refresh))//实例化一个工具条按钮对象,它将作为新的的导航按钮        self.navigationItem.leftBarButtonItem = leftBar//将导航栏左侧按钮,设置为新建的工具条按钮对象                let rightBar = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.save, target: self, action: #selector(FirstSubViewController.save))//为导航栏右边的按钮设置新的样式        self.navigationItem.rightBarButtonItem = rightBar//将导航栏右侧按钮,设置为新建的工具条按钮对象                let label = UILabel(frame: CGRect(x: 0, y: 0, width: 180, height: 30))//新建标签对象,用于显示标题区域的文字        label.text = "Happy Day"//设置标签对象的文字内容        label.textAlignment = NSTextAlignment.center//将标签对象的文字对齐方式设置为居中对齐        self.navigationItem.titleView = label//将标签视图对象设置为导航栏的标题区



    @objc func refresh() {        let alert = UIAlertController(title: "Information", message: "Refresh my feeling.", preferredStyle: UIAlertControllerStyle.alert)//创建一个警告弹出窗口        //创建一个按钮,作为提示窗口中的[确定]按钮,点击时关闭提示窗口        let action = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)        alert.addAction(action)//将确定按钮添加到提示窗口中        self.present(alert, animated: true, completion: nil)//在当前视图控制器中,展示提示窗口    }        @objc func save() {        print("Saving...")    }