gpt4 book ai didi

swift - UINavigationController 的工具栏不显示项目

转载 作者:行者123 更新时间:2023-11-30 10:50:47 24 4
gpt4 key购买 nike

我有一个自定义 UINavigationController (YAKMainNavigationController),其启用的工具栏显示在我的应用程序层次结构的底部。我尝试将它用作选项卡栏,通过自定义按钮 (YAKFadeButton) 在我的应用程序中的不同页面之间切换。我使用 YAKMainNavigationController.swift 中的以下代码将项目添加到工具栏:

override func viewDidLoad() {
addToolbarItems()
}

func addToolbarItems() {
var items = [UIBarButtonItem]()
items.append(UIBarButtonItem(customView: YAKFadeButton(normalImage: UIImage(named: "computer"), highlightedImage: UIImage(named: "computer1"), fadeDuration: 0.5, alignment: UIStackView.Alignment.center)))
items.append(UIBarButtonItem(customView: YAKFadeButton(normalImage: UIImage(named: "bell"), highlightedImage: UIImage(named: "bell1"), fadeDuration: 0.5, alignment: UIStackView.Alignment.center)))
items.append(UIBarButtonItem(customView: YAKFadeButton(normalImage: UIImage(named: "message"), highlightedImage: UIImage(named: "message1"), fadeDuration: 0.5, alignment: UIStackView.Alignment.center)))
items.append(UIBarButtonItem(customView: YAKFadeButton(normalImage: UIImage(named: "user"), highlightedImage: UIImage(named: "user1"), fadeDuration: 0.5, alignment: UIStackView.Alignment.center)))

setToolbarItems(items, animated: false)
setToolbarHidden(false, animated: false)
toolbar.tintColor = UIColor.white

print(items)
print(toolbarItems as Any)
}

由于我无法辨别的原因,这些项目没有显示。我已经捕获了 UI 层次结构,并且项目甚至不在那里,但 toolbarItems 数组确实包含这些项目。上述代码的控制台输出如下:

[<UIBarButtonItem: 0x1028272a0> view=<YAK.YAKFadeButton: 0x102825a20; baseClass = UIControl; frame = (0 0; 0 0); layer = <CALayer: 0x283059740>>, <UIBarButtonItem: 0x102829370> view=<YAK.YAKFadeButton: 0x1028288f0; baseClass = UIControl; frame = (0 0; 0 0); layer = <CALayer: 0x28305a060>>, <UIBarButtonItem: 0x10282aba0> view=<YAK.YAKFadeButton: 0x10282a120; baseClass = UIControl; frame = (0 0; 0 0); layer = <CALayer: 0x28305a860>>, <UIBarButtonItem: 0x10282cc00> view=<YAK.YAKFadeButton: 0x10282c180; baseClass = UIControl; frame = (0 0; 0 0); layer = <CALayer: 0x28305b060>>]
Optional([<UIBarButtonItem: 0x1028272a0> view=<YAK.YAKFadeButton: 0x102825a20; baseClass = UIControl; frame = (0 0; 0 0); layer = <CALayer: 0x283059740>>, <UIBarButtonItem: 0x102829370> view=<YAK.YAKFadeButton: 0x1028288f0; baseClass = UIControl; frame = (0 0; 0 0); layer = <CALayer: 0x28305a060>>, <UIBarButtonItem: 0x10282aba0> view=<YAK.YAKFadeButton: 0x10282a120; baseClass = UIControl; frame = (0 0; 0 0); layer = <CALayer: 0x28305a860>>, <UIBarButtonItem: 0x10282cc00> view=<YAK.YAKFadeButton: 0x10282c180; baseClass = UIControl; frame = (0 0; 0 0); layer = <CALayer: 0x28305b060>>])

非常感谢任何有关显示这些按钮的帮助,谢谢。

最佳答案

这里的解决方案可能会有所帮助:https://stackoverflow.com/a/29119376/1444152 - 设置self.toolbarItems

关于swift - UINavigationController 的工具栏不显示项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54590218/

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