Milan Nosáľ Milan Nosáľ - 1 month ago 6
Swift Question

How to show titles for UIToolBar items

Is there a standard way to enable showing title to toolbar items in

UIToolBar
?
UIBarButtonItem
has properties for both image and title, but when I set them, only image appears. Is there a way to present also a title (similarly to standard Phone application in iOS)?

My code:

let settings = UIBarButtonItem(image: #imageLiteral(resourceName: "settingsEmpty").withRenderingMode(.alwaysTemplate), style: .plain, target: self, action: nil)
settings.title = "Settings"
toolbarItems = [settings]

Answer Source

No that is not available in the standard control, you can only show image or title. You must make a custom control that does that - for the UIBarButtonItem you can set the customView (and as toolbar might turn out to be too small you might need to customize its height too). The purpose of the title is to be shown if there is no image, or to be read to users that use VoiceOver to navigate the app.