This is an issue with UILabel in iOS7 and iOS8, it does not present in iOS9. This odd UILabel behaviour is experienced with different fonts, in Xcode versions 6 and 7 with Swift, using the simulator and device.
Problem:
I have a UILabel that has a center text alignment. At different font sizes, some lines of text stop being center aligned and snap to left alignment. It is subtle but noticeable.
In the images below:
LEFT: all lines of text are centered neatly.
MIDDLE: after increasing the font size, the third line from the top snaps more to the left instead of remaining centered. (Notice more blue space on right.)
RIGHT: after increasing the font size a little more, both the second and third line from the top snap to the left instead of remaining centered. (Notice more blue space on right.)
Questions:
- What explains what might be the cause of this unusual alignment behaviour in iOS7 and iOS8 but not iOS9?
- How can I ensure that all lines are forced to remain center aligned perfectly regardless of the font type or font size used?
- What is the bug fix or work around for this in iOS7 and iOS8 so that apps created using UILabel centre aligned don’t feature the bug?