How to Use Sf Symbols in iOS 12 and Below

How to use SF Symbols in iOS 12 and below?

You can not use SFSymbols natively in iOS versions older than iOS 13 (see Apple's Human Interface Guidelines for SF Symbols).

However, if you are interested in using the graphics you can use the SFSymbols app to export SVG versions of the icon. Then use some graphics tool to convert them to PNG icons you can import into your asset catalog.

Screenshot how to export SVG from SFSymbols app on Mac.

Swift SF Symbols - only available in iOS 13.0 or newer error

Using SFSymbols is only available from iOS 13, however some specific symbols can also have higher deployment version (14 or 15) Check your project version in your App Target "General" tab and minimum deployment of your desired symbol. If you want to use symbols for lower iOS you should mark creating image with if #available(iOS 13.0, *) as you mentioned. If you want to make fallback image for lower iOS , your only option is to create separate asset with UIImage(named: "heart.jpeg") . You can also export your symbols manually adding it to Assset catalogue, however keep in mind that you need to convert it from SVG format so some other format, because iOS lower than version 13 also does not support SVG preserving vector data. exporting symbol

Use SF Symbols system image for static UIApplicationShortcutItem

Use UIApplicationShortcutItemIconSymbolName instead of UIApplicationShortcutItemIconFile in your Info.plist.

Is there a way to use a specific locale for a SF Symbol which is different from the current locale?

If someone wants to do this for any locale except English, then the answer from @wakel would be the better option.

For locale English, as @JoakimDanielson suggested in a comment, I have done this by downloading SF Symbols app and by exporting the required SF Symbol as a custom symbol template

SF Symbols app -> File -> Export Custom Symbol Template

This custom symbol is without any locales by default, which can be added to Assets of the project. Once it has added, you can use it as any other image asset you added using UIImage(named:)

let image = UIImage(named: "textbox")!.withConfiguration(UIImage.SymbolConfiguration(pointSize: 30, weight: .regular))
button.setImage(image, for: .normal)

The official Apple documentation for exporting symbols from SF Symbols app is here
https://developer.apple.com/documentation/uikit/uiimage/creating_custom_symbol_images_for_your_app

Is there a way to use SF Symbols in macOS SwiftUI development?

SF Symbol are now available with macOS 11.

SF Symbols are available in iOS 13 and later, macOS 11 and later, watchOS 6 and later, and tvOS 13 and later.

Here is how you use it:

NSImage(systemSymbolName: "hammer", accessibilityDescription: nil)

If you want to support macOS 10.15 and below you have to use the SF Symbols Mac app and export the symbol as SVG and import it back to an asset file in your Xcode project. You can get the app from here.



Related Topics



Leave a reply



Submit