To run the example project, clone the repo, and run
pod install from the Example directory first.
WordWrapLabel is available through CocoaPods. To install it, simply add the following line to your Podfile:
A UILabel subclass that really makes sure that every word in the label´s text fits into one line.
The standard UILabel can automatically adjust the scale of the font size to make the whole text fit the label bounds but it doesn´t take into account the actual length of the different words of the given text. This results in words being broken up into multiple lines because they are too long to fit one line.
The WordWrapLabel finds the suitable font size to make every word of the given text fit into one line.
It also makes sure that the text fits into the whole bounds of the label when there is a line number or height restriction.
To use WordWrapLabel just import the module in your code.
Then use it as the custom UILabel subclass in interface builder or initialize it in code.
You can define a minimum and maximum font size which will be taken into account when determining the right font size for the label. The search will start at the
maximumFontPointSize and then reduce the font size until either every word fits one line or
minimumFontPointSize is reached.
minimumFontPointSize can be set in interface builder or in code.
wordWrapLabel.maximumFontPointSize = 25 // Default is 40 wordWrapLabel.minimumFontPointSize = 10 // Default is 1
Philipp, [email protected]
WordWrapLabel is available under the MIT license. See the LICENSE file for more info.