gpt4 book ai didi

ios - backBarButtonItem 显示图像不正确

转载 作者:行者123 更新时间:2023-11-28 14:29:03 26 4
gpt4 key购买 nike

我正在为 backBarButtonItem 使用带有图像的自定义 UIBarButtonItem。我发现了奇怪的行为,因为除了我的图像之外,还显示了默认的箭头图标。

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
navigationItem.backBarButtonItem = UIBarButtonItem(image: #imageLiteral(resourceName: "BackButtonIcon"), style: .plain, target: nil, action: nil)
}

@IBAction private func push(_ button: UIButton) {
let secondViewController = SecondViewController()
navigationController?.pushViewController(secondViewController, animated: true)
}

}

class SecondViewController: UIViewController {


override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
}

}

结果是 enter image description here UI debugger

最佳答案

尝试使用:

navigationBar.backIndicatorImage = #imageLiteral(resourceName: "BackButtonIcon")

navigationController?.navigationBar.backIndicatorTransitionMaskImage = #imageLiteral(resourceName: "BackButtonIcon")

navigationItem.backBarButtonItem = UIBarButtonItem(title: "Title", style: UIBarButtonItemStyle.plain, target: nil, action: nil)

导航栏有一个背景图像属性以及一个 UINavigationItem 的 backItem 属性。您可以阅读更多here .

编辑:

在源 View Controller 而不是目标 Controller 中使用此代码。

关于ios - backBarButtonItem 显示图像不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51366378/

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