gpt4 book ai didi

快速隐藏后退按钮

转载 作者:行者123 更新时间:2023-11-28 11:37:02 25 4
gpt4 key购买 nike

我需要隐藏后退按钮并粘贴另一个按钮

self.navigationItem.setHidesBackButton(true, animated: false)
self.navigationItem.hidesBackButton = true
self.navigationController?.navigationItem.hidesBackButton = true
self.navigationController?.navigationBar.topItem?.hidesBackButton = true

self.tabBarController?.navigationController?.navigationItem.hidesBackButton = true
self.tabBarController?.navigationController?.navigationItem.setHidesBackButton(true, animated: false)
self.tabBarController?.navigationItem.hidesBackButton = true

let backButton1 = UIBarButtonItem (title: "Button", style: .plain, target: self, action: #selector(GoToBack))
self.navigationItem.leftBarButtonItem = backButton1
self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(GoToBack))

self.tabBarController?.navigationItem.setLeftBarButtonItems([backButton1], animated: true)

但是这段代码不起作用,后退按钮没有隐藏或替换为另一个按钮

我该如何解决这个问题?

像这样显示这个vc

self.navigationController?.pushViewController(viewcontroller, animated: true)

最佳答案

首先,在您的项目中创建BaseViewController,并在viewDidLoad中设置backButton隐藏代码和添加自定义后退按钮代码。

之后,您项目的所有 Controller 都应继承自 BaseViewController,以便为所有 Controller 启用新的后退按钮。

BaseViewContorller

override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.hidesBackButton = true
self.setBackButton()// Set Custom back button
}

设置自定义后退按钮代码

//Add Custom Back Button
fileprivate func setBackButton() {
let button = UIButton(type: UIButton.ButtonType.custom) as UIButton
button.frame = CGRect(x: 0, y: 0, width: 44, height: 44)
button.contentHorizontalAlignment = .fill
button.contentVerticalAlignment = .fill
button.imageView?.contentMode = .center
button.contentEdgeInsets = UIEdgeInsets(top: 0, left: -10, bottom: 0, right: 0)

button.setImage(UIImage(named: "backButton.png"), for: .normal)
button.addTarget(self, action: #selector(btnBackActionHandler(_:)), for:.touchUpInside)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: button)

}


@objc func btnBackActionHandler(_ sender : AnyObject) {
self.navigationController?.popViewController(animated: true)
}

关于快速隐藏后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54884357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com