Gen*_*ley 27 unicode nsstring ios sf-symbols
我对如何在 iOS 项目的文本中使用 SF 符号感到困惑。我有一个 UIButton 使用一个符号就好了UIImage systemImageNamed:
。我想在另一个视图中显示有关该按钮的消息和一些文本。我认为我应该能够使用对该符号的 Unicode 引用,但它没有呈现。我的理解是这些符号位于私人使用区域中,但我无法使用类似的代码渲染它们@"Press the \U0010057C button."
我曾尝试将 SFSymbolsFallback.ttf 字体文件导入到我的项目中。
我希望看到符号呈现,但我得到一个 ? 反而。
Mic*_*cio 57
这对我有用:
let imageAttachment = NSTextAttachment()
imageAttachment.image = UIImage(systemName: "checkmark.circle")
let fullString = NSMutableAttributedString(string: "Press the ")
fullString.append(NSAttributedString(attachment: imageAttachment))
fullString.append(NSAttributedString(string: " button"))
label.attributedText = fullString
Run Code Online (Sandbox Code Playgroud)
结果:
小智 7
我一直在努力解决如何使用 CoreText 渲染 API 使用 SF Symbol 字形的相同问题。在 MacOS 上,“SF Pro Text”字体包含 7500 多个字形,包括 SF Symbol 字形。在 iOS 上,系统字体只有约 2800 个字形,似乎不包括新的 SF Symbol 字形。除了在项目本身中包含字体(我相信这违反了 Apple 的许可),我还没有找到一种使用它们的 Unicode 字符值呈现这些字形的方法。
归档时间: |
|
查看次数: |
8822 次 |
最近记录: |