Swift - 修改导航栏“返回”按钮文字,图标

2017-05-16  本文已影响0人  彧哥哥

http://www.hangge.com/blog/cache/detail_957.html

        let leftBarBtn = UIBarButtonItem(title: "", style: .plain, target: self,action: #selector(backItemPressed))
        leftBarBtn.image = UIImage(named: "箭头后退")
        //用于消除左边空隙,要不然按钮顶不到最前面
        let spacer = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil,action: nil)
        spacer.width = -10;
        self.navigationItem.leftBarButtonItems = [spacer, leftBarBtn]
    func backItemPressed() {
        if webView.canGoBack {
            webView.goBack()
        }else{
            if let nav = self.navigationController {
                nav.popViewController(animated: true)
            }
        }
    }
上一篇下一篇

猜你喜欢

热点阅读