gpt4 book ai didi

ios - 为应用程序中的所有外观自定义后退按钮

转载 作者:搜寻专家 更新时间:2023-11-01 06:28:34 25 4
gpt4 key购买 nike

我想通过将文本设置为“后退”并移除箭头(即使只是移除箭头也可以)来更改应用程序中所有后退按钮的外观。我正在尝试找到一种方法来为应用程序中的所有 View Controller 全局执行此操作,同时还保留功能(我不想创建 UIBarButtonItem 的新实例并且必须设置选择器)。

我创建了一个自定义 UINavigationController 并尝试使用 navigationItem.backBarButtonItem?.title = "Back" 设置后退按钮标题,但没有成功。有什么正确的建议吗?

最佳答案

只需创建 CustomNavigationController 然后在重写 open func pushViewController(_ viewController: UIViewController, animated: Bool) 执行 controlClearBackTitle 方法

然后使用 CustomNavigationController 在您的应用中修复它

enter image description here

import UIKit

class CustomNavigationController: UINavigationController {

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

override open func pushViewController(_ viewController: UIViewController, animated: Bool) {
controlClearBackTitle()
super.pushViewController(viewController, animated: animated)
}

override open func show(_ vc: UIViewController, sender: Any?) {
controlClearBackTitle()
super.show(vc, sender: sender)
}

func controlClearBackTitle() {

self.navigationBar.backIndicatorImage = UIImage()
self.navigationBar.backIndicatorTransitionMaskImage = UIImage()
topViewController?.navigationItem.backBarButtonItem = UIBarButtonItem(title: "AnyTitle", style: .plain, target: nil, action: nil)

}
}

关于ios - 为应用程序中的所有外观自定义后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50492215/

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