Xcode9学习笔记21 - 自定义导航按钮UINavigationController

        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...")
    }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值