UINavigationController的工具栏未显示项目

时间:2019-02-08 10:17:52

标签: swift

我有一个自定义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>>])

非常感谢您提供这些按钮的显示帮助,谢谢。

1 个答案:

答案 0 :(得分:0)

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