是否可以在UIImage之外使用SF符号? [英] Is it possible to use SF Symbols outside of UIImage?

查看:32
本文介绍了是否可以在UIImage之外使用SF符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对如何在iOS项目中的文本中使用SF符号感到困惑.我有一个UIButton,使用 UIImage systemImageNamed:可以很好地使用符号.我想显示有关该按钮的消息,并在另一视图中显示一些文本.我以为我应该能够使用对该符号的Unicode引用,但它不会呈现.我的理解是这些符号位于专用区域"中,但是我无法使用 @按\ U0010057C按钮."

I'm confused on how to use SF Symbols in text in an iOS project. I have a UIButton that uses a symbol just fine using UIImage systemImageNamed:. I would like to display a message about that button with some text in another view. I thought I should be able to use the Unicode reference to that symbol, but it doesn't render. My understanding is that these symbols are in the Private Use Area, but I cannot get them to render using code like @"Press the \U0010057C button."

我尝试将SFSymbolsFallback.ttf字体文件导入到我的项目中.

I have tried importing the SFSymbolsFallback.ttf font file into my project.

我希望看到该符号已渲染,但是我得到了?代替.

I would expect to see the symbol rendered, but I get a ? instead.

推荐答案

这对我有用:

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

结果:

这篇关于是否可以在UIImage之外使用SF符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆