I'm using UIDocumentBrowserViewController
. This view controller automatically creates a TabView
with navigation titles and up to two trailing navigation bar items.
To visualize this, open the Files app by Apple on an iPhone.
I want to do the following:
- Add a third button and place it farthest on the trailing side.
- Keep all three buttons blue (the default color), but adjust the color of the navigation title to use the primary text color (it is also currently blue, by default)
Button Order
If my button is represented by C
, then the order from left-to-right or leading-to-trailing should be A B C
.
I tried to add it by using additionaltrailingnavigationbarbuttonitems
:
class DocumentBrowserViewController: UIDocumentBrowserViewController, UIDocumentBrowserViewControllerDelegate
{
override func viewDidLoad()
{
super.viewDidLoad()
let button = UIBarButtonItem(...)
additionalTrailingNavigationBarButtonItems.append(button)
}
}
This always adds it as the leftmost trailing item. The order when the view loads is C A B
, where C
represents my button.
Here are some things I've tried:
- Add it in
viewWillAppear
- same results. - Add it in
viewDidAppear
- same results. - Add it using
rightBarButtonItems
- does not show up at all. insert
itat: 0
instead of appending it - same results.- Add it with a delay using
DispatchQueue.main.async
- same results.
After some experimentation, I realized that the arrays referenced by additionalTrailingNavigationBarButtons
and rightBarButtonItems
seem to be empty, other than my own button. This is the case even if the DispatchQueue
delay is so long that the view has already rendered and the two default buttons are clearly visible. So I'm not sure how to place my button relative to these, since I can't figure out where they actually are in the view controller's properties.
How do I put my button farther to the trailing/right side of these two default buttons?
Title Color
The navigation titles created by UIDocumentBrowserViewController
are blue when not in their inline format. I want them to use the primary text color instead.
In viewDidLoad
, I could do something like this:
UINavigationBar.appearance().tintColor = UIColor.label
This will change the title color to white or black, but it will also change the color of the buttons. I've tried various approaches like titleTextAttributes
, and none of them seem to work with this view controller.
How do I change just the color of the navigation title, and not the color of the navigation bar items?