Question

The goal is to be able to insert images with text when sharing text into an SMS Message from the App as well as in e-mails. Like it is in the picture below. When I try to share images with the UIActivityViewController the images appear on the next line and not next to the text. Is it possible to embed images in text and e-mail like the built in Emoji text?Inline Emoji

Was it helpful?

Solution

The contents of text messages are just that, text (that is, a sequence of Unicode code points.) The emoji images you see in the screenshot come from a system font installed on all iOS devices, and are represented in the text as unicode code points, just like the other regular letters in the same message.

If you want to embed custom images into text fields in your app, you can create a custom font that includes the desired graphics (for some code points in the Unicode private use area,) include the font in your app as an asset, configure your text fields to use that font, and then provide some UI for the user to type those code points in.

But remember that this will only work on devices that have your custom font installed, and in apps that choose to use that custom font to display the text — so essentially only in your own app. So for example if you'd send the text in an email or iMessage/SMS to another device, your custom graphics would not work unless a) the receiving device has your custom font installed system-wide, and b) the app displaying the text resolves the Unicode private use area code points you chose to use for your images to this custom font of yours.

If you only want to embed images into text fields within your own app, on iOS 7 and later you can use the text attachments feature that TextKit supports.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top