Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBarButtonItem Initializer with Image and Title does not show Title

I am using init(title:image:primaryAction:menu:) of a UIBarButtonItem Apple Documentation on a Toolbar with the hope of showing a button with both image and title. Does anyone know why the title does not show? I am not looking for a custom implementation that can add a UIBarButtonItem with title and image. I have seen plenty on Stackoverflow. I just want to use this initializer if it works.

I have a UITableViewController subclass and I have added this code to the viewDidLoad

navigationController?.isToolbarHidden = false
let barButtonItem = UIBarButtonItem(title: "New Item", image: UIImage(systemName: "plus.circle.fill"), primaryAction: nil, menu: nil)
toolbarItems = [barButtonItem]
like image 590
Dogahe Avatar asked Nov 15 '22 03:11

Dogahe


1 Answers

My guess is that since public convenience init(title: String? = nil, image: UIImage? = nil, primaryAction: UIAction? = nil, menu: UIMenu? = nil) is a convenience init, and the fact that there is no init that initialize with both title and image, then using both at the same time is not supported. It's merely a convenience on using primaryAction and menu then having title and image.

like image 91
CiNN Avatar answered Mar 30 '23 00:03

CiNN