TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Oct 2017 |
SwiftSwift Version | 4.0 |
SPMSupports SPM | ✗ |
Maintained by Jeff Burt.
EvenlyWrappedLabel
is a UILabel
subclass that will vertically distribute text or attributed text evenly across any number of lines, preventing text from grouping up at the top and also preventing single word orphans from taking up the entire bottom line.
Examples:
This text:
This sentence has a lot of words on
the top line.
Becomes:
This sentence has a lot
of words on the top line.
This text:
This sentence has a single
orphan.
Becomes:
This sentence has
a single orphan.
Works with iOS 9.0+ and Xcode 9.0.0+.
drawText(in:)
internally (as opposed to creating subviews), so any UILabel
reference can be replaced with EvenlyWrappedLabel
and Everything Will Just Work™.useEveryLine
option to force shorter text to take up all available lines.Swap any UILabel
reference with EvenlyWrappedLabel
:
class ViewController {
let label = UILabel()
}
import EvenlyWrappedLabel
class ViewController {
let label = EvenlyWrappedLabel()
}
Set label.useEveryLine = true
to spread the text across all numberOfLines
, even if the text isn't long enough to do so by default.
Example:
When numberOfLines
= 3
, and useEveryLine
= true
, the following text:
This only takes up one line.
Becomes:
This only
takes up
one line.
If you prefer not to use CocoaPods, you can integrate EvenlyWrappedLabel
into your project manually.
EvenlyWrappedLabel
is developed by Jeff Burt at StockX and is released under the MIT license. See the LICENSE
file for details.
Feel free to follow me on my personal Twitter account. If you find any problems with the project or have ideas to enhance it, feel free to open a GitHub issue and/or create a pull request.