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

不废话,上代码:

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 添加自定义返回按钮(去掉返回按钮的文字))