Friday 11 October 2019

iOS: Natural text alignment doesn't mean what you think it means

So it turns out that natural text alignment in iOS doesn't mean "left-align left-to-right text and right-align right-to-left text" as it does in Android. For example, if I put English text in a UILabel I'd expect it to be left-aligned and if I put Arabic text in a UILabel I'd expect it to be right-aligned. But no. This is not how it works in iOS. Instead natural text alignment in iOS means "left-align text if the device's language is set to a left-to-right language and right-align text if the device's language is set to a right-to-left language". So, for example, if I set the device's language to English then the text in the UILabel will be left-aligned regardless of its content and if I set the device's language to Arabic then the text in the UILabel will be right-aligned regardless of its content.

For a super simple iOS application which demonstrates this see here.