0

I have a custom UINavigationController (YAKMainNavigationController) with the toolbar enabled shown at the base of my app's hierarchy. I am attempting to use it as a tab bar to switch between different pages in my app with custom buttons (YAKFadeButton). I am using the code below in YAKMainNavigationController.swift to add the items to the toolbar:

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)
}

The items are not displayed for a reason that I cannot discern. I've captured the UI hierarchy and the items are not even in there, yet the toolbarItems array does contain the items. The console output for the code above is as follows:

[<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>>])

Any help with getting these buttons to show is greatly appreciated, thank you.

1 Answer 1

0

The solution here might help: https://stackoverflow.com/a/29119376/1444152 - set self.toolbarItems.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.