IOS11 之后隐藏导航栏返回按钮文字, 页面隐藏导航栏返回出现黑块问题

隐藏返回文字

UIBarButtonItem.appearance()
               .setBackButtonTitlePositionAdjustment(UIOffset( horizontal:                 
               -200,vertical: 0), for: .default)
        

上面的方法有个问题是返回的时候这个会显示出来然后又消失,可以将文字颜色设置为透明,并且将普通模式的文字和高亮模式的文字都改为透明

UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.clear], for: .normal)
UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.clear], for: .highlighted)

隐藏当前页面的导航栏,并且解决返回的时候出现黑块的问题

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.setNavigationBarHidden(true, animated: animated)
    }
override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        navigationController?.setNavigationBarHidden(false, animated: animated)
    }

你可能感兴趣的:(ios,swift,navigation,swift,ios,xcode)