My use case for this was an font that only contained symbols/glyphs, and then I'd use them NSAttributedString.
My workaround was to replace these with images in my asset catalog, then use NSTextAttachment to embed that image.
let attachment: NSTextAttachment
if #available(iOS 13, *) {
attachment = NSTextAttachment(image: image.withRenderingMode(.alwaysTemplate))
}
else {
attachment = NSTextAttachment()
attachment.image = image.withRenderingMode(.alwaysTemplate)
}
let imageString = NSMutableAttributedString(attachment: attachment)
imageString.addAttribute(.foregroundColor, value: color, range: NSRange(location: 0, length: imageString.length))
NSTextAttachment isn't available on watchOS.
To set the colour of the image attachment, use addAttribute afterwards .foregroundColor.