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

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

作者: 彧哥哥 | 来源:发表于2017-05-16 15:17 被阅读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)
                }
            }
        }
    

    相关文章

      网友评论

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

          本文链接:https://www.haomeiwen.com/subject/mgylxxtx.html