Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use SF Symbols outside of UIImage?

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."

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.

like image 673
Gene McCulley Avatar asked Oct 11 '19 12:10

Gene McCulley


People also ask

Where can I use SF Symbols?

How to place SF Symbols next to text. SF Symbols work great when used inside text, particularly when they contain common symbols such as error crosses, check marks, calendars, and similar.

Can I use SF Symbols on my website?

You are not able to use this icons on the websites as license of SF symbols do not allow use those symbols externally than apple's products.


1 Answers

This works for me:

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 

Result:

enter image description here

like image 114
Michcio Avatar answered Sep 25 '22 09:09

Michcio