simonbs
simonbs

Reputation: 8042

Display Emoji icons in Mac app

I want the user to have easy access to Emoji icons in a small chat I am making for the company I'm working at. Therefore, I want to make a panel which shows the available Emoji icons. To do this, I am using an NSCollectionView. Now, I need to pass a string which is shown in an NSTextField. This string must contain one Emoji icon.

I can't figure out how to write this Emoji icon in unicode in a string. Everything I have tried just shows a strange symbol instead of the icon.

Can anyone tell me, how I can put an Emoji icon into an NSString?

Upvotes: 1

Views: 1380

Answers (1)

Dietrich Epp
Dietrich Epp

Reputation: 213578

📱 You want emoji 😄?

🐷🐻🐨🐸 They're in Unicode now 🐸🐨🐻🐷

If you open up the 💻Character Viewer💻 you can actually paste them directly into your source code. If you'd rather, you can encode them in hexadecimal (\U0001F431 for cat face) by looking them up in the Unicode code charts (especially the chart for the U+1F300 block).

If you want to make sure they appear in color, you'll need to select the "Apple Color Emoji" font for the Emoji. You can use NSAttributedString to set the font on a per-character basis.

Upvotes: 6

Related Questions