Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get system images programmatically? (example: disclosure chevron)

Tags:

macos

ios

cocoa

I want to create UIImageView with some system-image in it. (Example: the disclosure chevron image, etc.). How can I do so programmatically?

Note: I don't want to download the image and add it to the project, I want to fetch it from the user programmatically / from the Interface Builder.

like image 242
Nili Avatar asked Sep 10 '13 11:09

Nili


3 Answers

From iOS 13 and Xcode 11 you can get system images by giving system name.

let image = UIImage(systemName: "info.circle")

icons

Reference : UIImage Apple Documentation

like image 155
Ashish Kakkad Avatar answered Nov 20 '22 20:11

Ashish Kakkad


If you mean you can to set the button to use the system disclosure icon, just do as @middaparka suggested and use this:

UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

If you're asking how you can access the image directly, you can't do that. This is your only option: Use default apple icons for pdfs and docs in iOS app?

like image 20
Mick MacCallum Avatar answered Nov 20 '22 20:11

Mick MacCallum


I think iOS-Artwork-Extractor is the tool you are looking for. It lets you extract the artwork into png files.

There is no clean programmatical way to access the images of system buttons. Quote from the documentation of the UIButton.imageView property:

The value of the property is nil for system buttons.

You may do an off screen rendering of the views and extract the resources on the fly but that's a very shaky approach. It's better to extract every asset you need and use them as intended. You'll suffer much more in the end with the programmatic way.

like image 42
allprog Avatar answered Nov 20 '22 20:11

allprog