EvenlyWrappedLabel 1.3.0

EvenlyWrappedLabel 1.3.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Oct 2017
SwiftSwift Version 4.0
SPMSupports SPM

Maintained by Jeff Burt.







Description

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:

  1. 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.
    
  2. 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+.

Contents

  1. Features
  2. Usage
  3. Installation
  4. License
  5. Contact

Features

  • Works with all devices running iOS 9+.
  • Uses drawText(in:) internally (as opposed to creating subviews), so any UILabel reference can be replaced with EvenlyWrappedLabel and Everything Will Just Work™.
  • Works with any number of lines, any text alignment and attributed text.
  • Works with autolayout and honors intrinsic sizing.
  • Works with labels created in code and in Interface Builder.
  • useEveryLine option to force shorter text to take up all available lines.
  • Example app with lots of real-time configurations that lets you see the text wrap as you type.

Example Project Screenshot

Usage

Set up

Swap any UILabel reference with EvenlyWrappedLabel:

In code


Before:
class ViewController {
    let label = UILabel()
}
After:
import EvenlyWrappedLabel

class ViewController {
    let label = EvenlyWrappedLabel()
}

In Interface Builder


Before:

Interface Builder Screenshot - Before

After:

Interface Builder Screenshot - After

(Optional) Use Every Line

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.
    

Installation

Manually

If you prefer not to use CocoaPods, you can integrate EvenlyWrappedLabel into your project manually.

License

EvenlyWrappedLabel is developed by Jeff Burt at StockX and is released under the MIT license. See the LICENSE file for details.

Contact

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.