Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 458
Apollo Avatar asked Oct 14 '25 17:10

Apollo


2 Answers

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.

like image 71
Frankenstein Avatar answered Oct 17 '25 07:10

Frankenstein


To access system icons:

let image = UIImage(systemName: "wrench")
button.setImage(image, for: .normal)
like image 34
rafsanahmad007 Avatar answered Oct 17 '25 09:10

rafsanahmad007