Search code examples
iosswiftxcodecocoa-touchuibutton

How can I assign one of the built-in icons to a UIButton programatically?


In the storyboard of XCode 11.5 there are several icons in the "image" property of a UIButton. However, I can't find any references to these images in the documentation and when attempting to create a button programatically I can only find references to using images I put in the bundle myself. Is there a way of accessing these built-in images from the code? How?

enter image description here


Solution

  • They are SFSysmbol icons. If you're asking about an auto-complete in Xcode when adding images programmatically, there isn't one. But you can get the list of all the available SFSymbols from this app. And you can use UIImage(systemName:) initializer to access the available icons.