I am unable to change the prompt color on my navigation bar. I've tried the code below in viewDidLoad
, but nothing happens.
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
Am I missing something? Is the code above wrong?
I suggest using a custom
UINavigationBar
subclass and overridinglayoutSubviews
:Basically I'm enumerating all UILabels in the subview hierarchy and check if their text matches the prompt text. Then we set the textColor to the tintColor (feel free to use a custom color). That way, we don't have to hardcode the private
_UINavigationBarModernPromptView
class as the prompt label's superview. So the code is be a bit more future-proof.Converting the code to Swift and implementing the helper methods
recursiveSubviewsOfKind:
andselectFirstObjectUsingBlock:
are left as an exercise to the readerI've found next work around for iOS 11. You need set at
viewDidLoad
navigationItem.prompt = UINavigationController.fakeUniqueText
and after that put next thingI was able to make the prompt color white on iOS 11 was setting the barStyle to black. I set the other color attributes (like the desired background color) using the appearance proxy:
More complicated version to support old and new iOS
Try this out:->
You may use
It will be a temporary workaround until they'll fix it