ios - 是否可以在 UIImage 之外使用 SF 符号?

标签 ios unicode nsstring sf-symbols

我对如何在 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
结果:
enter image description here

关于ios - 是否可以在 UIImage 之外使用 SF 符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58341042/

相关文章:

ios - (Swift) 如何通过重新加载 UITableView 根据 UITextfield 输入(动画)显示/隐藏单元格?

ios - 以编程方式创建的 UISplitViewController 没有滑动手势来显示/隐藏 master

ios - 为什么我的 UISearchBar 在点击时会缩小?

objective-c - 如何检查 NSString 的最后一个字符

xcode - 如何在 Xcode Debugger 中打印 NSString 的地址

iphone - UITableViewCell AutoRelease 导致崩溃...?

php - MySQL utf8_通用字符映射表

string - 当 YAML 文件包含 unicode 字符(如 "a\u0000b")时,在 golang 中读取 YAML 文件

java - 使用 FileWriter (Java) 以 UTF-8 格式写入文件?

objective-c - 将 NSStrings 与 Ä,Ö,Ü 进行比较