Setting a letter spacing for a
Label in Android and iOS turned into an interesting research for me. I would expect that such a common task would be easily done with a help of a
Renderer or an
Effect. However, I was very surprised to discover that some platforms do not have a built-in support for setting letter spacing.
It turned out that setting letter spacing it is not possible on pre Lollipop (< 21) without hacks when on Lollipop+ there is a dedicated method: setLetterSpacing(). Luckily this SO post offered a creative solution:
.. method adds a space between each letter of the String and with SpannedString changes the TextScaleX of the spaces, allowing positive and negative spacing ..
The math in this solution is a bit weird and should be adjusted according to your specific needs. Otherwise it is doing it’s job nicely.
Checking the Distribution dashboard, it seems that 15.3% of users are using KitKat or older and 84.7% are using Lollipop or newer Android version. So hopefully very soon this recipe could be simplified🤞.
On iOS it is (as expected) a one-liner using attributedText property.
I combined the details described above into Effect: