如何以编程方式设置 iOS 13 个字形
How to set iOS 13 glyphs programmatically
从 iOS13 开始,Apple 提供了一堆字形,可以是 used "everywhere you can use an image".
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
的图像:
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
附加到图像名称,但没有任何区别。
我们如何以编程方式设置 iOS 13 个字形?
- 注意:我安装了 SF Symbols 应用程序并成功将字形设置为 UIBarButtonItems 的图像在情节提要。
替换:
UIImage(named: "square.and.arrow.up")
与:
UIImage(systemName: "square.and.arrow.up")
现在记录在 UIImage
从 iOS13 开始,Apple 提供了一堆字形,可以是 used "everywhere you can use an image".
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
的图像:
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
附加到图像名称,但没有任何区别。
我们如何以编程方式设置 iOS 13 个字形?
- 注意:我安装了 SF Symbols 应用程序并成功将字形设置为 UIBarButtonItems 的图像在情节提要。
替换:
UIImage(named: "square.and.arrow.up")
与:
UIImage(systemName: "square.and.arrow.up")
现在记录在 UIImage