美文网首页
IOS swift 添加自定义返回按钮(去掉返回按钮的文字)

IOS swift 添加自定义返回按钮(去掉返回按钮的文字)

作者: 笨小孩81 | 来源:发表于2019-03-26 00:20 被阅读0次

不废话,上代码:

func addCustomBackButton() {
        let leftBarBtn = UIBarButtonItem(title: "", style: .plain, target: self,action: #selector(UIViewController.backToPrevious))
        leftBarBtn.image = UIImage(named: "backIcon");
        leftBarBtn.imageInsets.left = -8;
        self.navigationItem.hidesBackButton = true;
        self.navigationItem.leftBarButtonItem = leftBarBtn;
    }

func backToPrevious(){
        if(self.navigationController?.childViewControllers[0] == self){
            self.dismiss(animated: true, completion:nil)
            return;
        }
        self.navigationController?.popViewController(animated: true)
     }

相关文章

网友评论

      本文标题:IOS swift 添加自定义返回按钮(去掉返回按钮的文字)

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