Starting with iOS 13, Apple is providing a bunch of glyphs which can be used "everywhere you can use an image".
You can use SF symbols to represent tasks and types of content in a variety of specific places, such as navigation bars, toolbars, tab bars, context menus, and Home Screen Quick Actions. Throughout the rest of your app, you can use a symbol everywhere you can use an image.
I therefore expected this code to set a glyph as a UIBarButtonItem
's image:
shareButton = UIBarButtonItem(
image: UIImage(named: "square.and.arrow.up"), // the name for the 'action' (Share) glyph
style: .plain,
target: self,
action: #selector(mySelector))
But the app crashed with nil as the image wasn't found.
I tried appending .png
to the image name, but it made no difference.
Replace:
UIImage(named: "square.and.arrow.up")
With:
UIImage(systemName: "square.and.arrow.up")
This is now documented in UIImage