gpt4 book ai didi

ios - swift3 中带有自定义标题的自定义导航后退按钮

转载 作者:行者123 更新时间:2023-11-28 08:06:16 26 4
gpt4 key购买 nike

我需要实现带有自定义背景图像和自定义标题的导航栏。例如:如果我在“使用 facebook 登录”页面,我需要在自定义背景图片之外显示“使用 facebook 登录”。为此,我遵循这样的代码:

let yourBackImage = UIImage(named: "back_button_image")
self.navigationController?.navigationBar.backIndicatorImage = yourBackImage
self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = yourBackImage
self.navigationController?.navigationBar.backItem?.title = "Custom"

但是我得到的输出是这样的:

enter image description here

注意:标题是当前页面的标题。

如何实现?

最佳答案

如果后退标题太长,iOS 会将其更改为“后退”。

但是,如果您添加左栏按钮项目 - 您可以将其设置为更长的长度。

long back

来自 Apple 文档:https://developer.apple.com/documentation/uikit/uinavigationcontroller

In cases where the title of a back button is too long to fit in the available space, the navigation bar may substitute the string “Back” for the actual button title. The navigation bar does this only if the back button is provided by the previous view controller. If the new top-level view controller has a custom left bar button item—an object in the leftBarButtonItem or leftBarButtonItems property of its navigation item—the navigation bar does not change the button title.

要执行此操作,请转到 Storyboard,在 Interface Builder 中,将一个 Bar Button Item 拖到导航栏中并设置其标题。

*请注意,您需要将它连接到您的 View Controller 以弹出它。

 @IBAction func pop(_ sender: UIBarButtonItem) {
_ = navigationController?.popViewController(animated: true)
}

关于ios - swift3 中带有自定义标题的自定义导航后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45019274/

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