我对如何在 iOS 项目的文本中使用 SF 符号感到困惑。我有一个使用 UIImage systemImageNamed:
的符号的 UIButton .我想在另一个 View 中显示有关该按钮的消息和一些文本。我认为我应该能够使用该符号的 Unicode 引用,但它不会呈现。我的理解是这些符号位于私有(private)使用区域,但我无法使用 @"Press the \U0010057C button."
之类的代码来渲染它们
我尝试将 SFSymbolsFallback.ttf 字体文件导入我的项目。
我希望看到呈现的符号,但我得到一个?反而。
最佳答案
这对我有用:
let imageAttachment = NSTextAttachment()
imageAttachment.image = UIImage(systemName: "checkmark.circle")
// If you want to enable Color in the SF Symbols.
imageAttachment.image = UIImage(systemName: "checkmark.circle")?.withTintColor(.blue)
let fullString = NSMutableAttributedString(string: "Press the ")
fullString.append(NSAttributedString(attachment: imageAttachment))
fullString.append(NSAttributedString(string: " button"))
label.attributedText = fullString
结果:关于ios - 是否可以在 UIImage 之外使用 SF 符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58341042/