init(systemName:compatibleWith:)
Creates an image object that contains a system symbol image appropriate for the specified traits.
Declaration
init?(systemName name: String, compatibleWith traitCollection: UITraitCollection?)Parameters
- name:
The name of the system symbol image.
- traitCollection:
The traits associated with the intended environment for the image. Use this parameter to ensure that the correct variant of the image is loaded. If you specify
nil, this method uses the traits associated with the main screen.
Mentioned in
Return Value
The object containing the image variant that matches the specified trait collection, or nil if no suitable image was found.
Discussion
Use this method to retrieve system-defined symbol images. To retrieve a custom symbol image you store in an asset catalog, use the init(named:in:compatibleWith:) method instead.
This method checks the system caches for an image with the name you specify and returns the variant of that image that’s best suited for traits.
If a matching image object isn’t in the cache, this method creates the image from the system symbol image. The system may purge cached image data at any time to free up memory. Purging occurs only for unused images that are in the cache.
To look up the names of system symbol images, download the SF Symbols app from Apple Design Resources.
See Also
Loading and caching images
Providing images for different appearancesConfiguring and displaying symbol images in your UICreating custom symbol images for your appinit(named:in:compatibleWith:)init(named:in:with:)init(named:in:variableValue:configuration:)init(named:)init(imageLiteralResourceName:)init(systemName:withConfiguration:)init(systemName:variableValue:configuration:)init(systemName:)init(resource:)Building high-performance lists and collection views