Workaround for UILabel Bug

If you are using a multi-line UILabel in your iOS project, you will run into this bug – at least as long as you’re using iOS 7 and set the headIndent property (filed the bug today): when you calculate the height of the UILabel, its intrinsic content size will be too small to fit all the text. Download code at the bottom of the page.

The buggy approach we are suppose to use is shown on the left, while the workaround is seen in all its glory to the right. As you have figured out, the table should show THE END as the final two words in each cell.



Download Source

You can download both projects below. And just to make it clear, this code was provided as a reply to a ticket I submitted to Apple. Though the code appears to work flawlessly, there is no guarantee that it is bug free. You can do whatever you want with the code; you take the risk if you choose use it.

Download the buggy Xcode project that reveals the iOS bug that returns the incorrect height for attributed UILabels with the headIndent property set.

Download the working Xcode project which provides the MyCoreTextLabel subclass that correctly handles attributed UILabels with the headIndent property set.

Bug and Extermination icons designed by Dmitry Baranovskiy from the Noun Project.

This article was posted in Games. Bookmark the permalink. Follow comments with the RSS feed for this post. Both comments and trackbacks are closed.