iOS | Android |
It is very common nowadays to express ourselves by using emojis. Instead of typing few words, we prefer to send one emoji that will express our feelings and emotions. Not sure that the other side will always get what we mean by sending a 🧞 , but that is another story.
In this article we will learn:
- How to use emojis in static content like Labels and Buttons
- How to define and use emoji in XAML only
- How to define and use emoji using C#
Emoji?
Emoji is represented by a single unicode character or a specific sequence of unicode characters.
Example: 🤔 is represented by U+1F914
.
In case you wonder about the format the Unicode Preface briefly explains it:
..an individual Unicode value is expressed as U+nnnn, where nnnn is a four-digit number in hexadecimal notation..
In case of sequence, concat all the unicode characters without spaces. Some emojis use U+200D ZERO WIDTH JOINER between emoji to make them behave like a single, unique emoji character.
Example: 👨⚕️ is represented by U+1F468 U+200D U+2695 U+FE0F
U+1F468
- man👨
U+200D
- ZWJ
U+2695
- medical symbol ⚕
U+FE0F
- variation selector
The full list of emojis can be found here.
Emoji in XAML
Since XAML is an XML-based markup language, we have to use XML escape character &#;
and we have to replace U+
prefix by x
for each part of our emoji :
Example:
If you need just a couple of emojis you may want to simply define all of them in XAML without involving any C# code at all.
Emoji in C#
Let’s define a class that will represent emoji:
It requires a single unicode character or sequence of characters as an input and simply overrides the ToString
. Please note that U+
prefix should be replaced with 0x
to specify hexadecimal notation.
Example of usage:
Example:
$"I am going to {bikingEmoji}!"
Conclusion
There are 2789 emojis available at the moment and this number is still in growth. Using emojis we can add more colours and a personal touch to our applications. So why not to use them 🤓?
The source code is available on github.
P.S.: Please keep in mind that Apple may reject applications using emojis as part of UI, more information can be found here and here.