获取SF Symbol的系统名称

Get system name of SF Symbol

我正在尝试获取 SF 符号的系统名称。 这是我的图片:

let image = UIImage(systemName: "checkmark.circle.fill")

以后如何获取该镜像的系统名称?

我还发现,当我打印图像描述时,它会打印符号名称和其他数据。有没有办法从那里提取名字?

<UIImage:0x600001d50900 symbol(system: checkmark.circle.fill) {20, 19} baseline=3.5,contentInsets={1, 1.5, 1, 1.5},alignmentRectInsets={-0.5, 0, -0.5, 0} config=<(null), traits=(UserInterfaceIdiom = Pad, DisplayScale = 2, DisplayGamut = P3, HorizontalSizeClass = Regular, VerticalSizeClass = Regular, UserInterfaceStyle = Light, UserInterfaceLayoutDirection = LTR, PreferredContentSizeCategory = L, AccessibilityContrast = Normal)>>

无法获取在 UIImage 实例中使用的图像,但解决方法是设置 "accessibilityIdentifier" 以便稍后使用。

let img = UIImage(named: "Cat")
img?.accessibilityIdentifier = "Cat"



print(img?.accessibilityIdentifier) // Outputs: Cat

更多来自: 如何获取UIImage中使用的Image Name?

使用这个扩展:

extension UIImage {

 var sfSymbolName: String? {
        guard let strSeq = "\(String(describing: self))".split(separator: ")").first else { return nil }
        let str = String(strSeq)
        guard let name = str.split(separator: ":").last else { return nil }
        return String(name)
    }
}