Use SF Symbols system image for static UIApplicationShortcutItem

早过忘川 提交于 2020-08-02 06:14:26

问题


When specifying home screen quick actions, UIApplicationShortcutItems, in your Info.plist, is there a way to use a system image from SF Symbols?

The docs noting the available iOS keys doesn't specify a key to do this, besides specifying one of the predefined enum cases from UIApplicationShortcutItemIconType such as UIApplicationShortcutIconTypeSearch.

It is possible to use a system image when creating dynamic quick actions via a new initializer UIApplicationShortcutIcon.init(systemImageName: String). Is there a Info.plist key that allows this for static quick actions?


回答1:


Use UIApplicationShortcutItemIconSymbolName instead of UIApplicationShortcutItemIconFile in your Info.plist.




回答2:


Seems like there is no way to directly use those. But since there are not much symbols that you need to use statically at the same time, here is the solution:

  1. Select the symbol you need and export it from SF Symbols.app:

  1. Import it in the Assets.xcassets:

  1. Use it's name for the key UIApplicationShortcutItemIconFile:

Result

I hope Apple add direct support for SF Symbols soon.




回答3:


I read the docs and tried several methods to get this working but the conclusion I reached is that this won't be possible for two main reasons:

  • SF Symbols are only available for native use on devices running iOS 13 or older.
  • Info.plist file can specify a platform and device type but you can't specify an OS version.

In Apple's documents it's also stated that:

You can use SF Symbols in apps running in iOS 13 and later, watchOS 6 and later, and tvOS 13 and later. To browse the full set of symbols, download the SF Symbols app.

This means that you are able to use these symbols but with a standard way. Here is what you can do:

  • Download the SF Symbols app from here.
  • Export the symbols you'd like to use as SVG files.
  • Add exported SVG files to your assets.
  • Use the asset name for the value of UIApplicationShortcutItemIconFile key.

This may not be the method you'd have hoped but it's a valid solution for using SF Symbols as shortcut icons so I hope this works for you.



来源:https://stackoverflow.com/questions/57139226/use-sf-symbols-system-image-for-static-uiapplicationshortcutitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!