如何以编程方式设置iOS 13字形 [英] How to set iOS 13 glyphs programmatically
问题描述
从iOS 13开始,Apple提供了一堆标志符号,它们可以为使用 在任何可以使用图像的地方".
Starting with iOS 13, Apple is providing a bunch of glyphs which can be used "everywhere you can use an image".
您可以使用SF符号在各种特定位置表示任务和内容类型,例如导航栏,工具栏,选项卡栏,上下文菜单和主屏幕快速操作.在应用程序的其余部分中,可以在任何可以使用图像的位置使用符号.
You can use SF symbols to represent tasks and types of content in a variety of specific places, such as navigation bars, toolbars, tab bars, context menus, and Home Screen Quick Actions. Throughout the rest of your app, you can use a symbol everywhere you can use an image.
因此,我希望此代码将字形设置为 UIBarButtonItem
的图像:
I therefore expected this code to set a glyph as a UIBarButtonItem
's image:
shareButton = UIBarButtonItem(
image: UIImage(named: "square.and.arrow.up"), // the name for the 'action' (Share) glyph
style: .plain,
target: self,
action: #selector(mySelector))
但是由于找不到图片,该应用程序崩溃并显示为nil.
我尝试将 .png
附加到图像名称,但这没什么区别.
But the app crashed with nil as the image wasn't found.
I tried appending .png
to the image name, but it made no difference.
- 注意:我安装了SF Symbols应用程序,并成功将字形设置为Storyboard中的UIBarButtonItems 的图像.
推荐答案
替换:
UIImage(named: "square.and.arrow.up")
使用:
UIImage(systemName: "square.and.arrow.up")
现在已在 UIImage
这篇关于如何以编程方式设置iOS 13字形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!