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.
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.
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With