Latest 1.3.0
Homepage https://github.com/StockX/EvenlyWrappedLabel
License MIT
Platforms ios 9.0
Authors

EvenlyWrappedLabel Logo

EvenlyWrappedLabel
Platform
Version
License

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

  • [x] Works with all devices running iOS 9+.
  • [x] Uses drawText(in:) internally (as opposed to creating subviews), so any UILabel reference can be replaced with EvenlyWrappedLabel and Everything Will Just Work™.
  • [x] Works with any number of lines, any text alignment and attributed text.
  • [x] Works with autolayout and honors intrinsic sizing.
  • [x] Works with labels created in code and in Interface Builder.
  • [x] useEveryLine option to force shorter text to take up all available lines.
  • [x] 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

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

CocoaPods 0.36 adds supports for Swift and embedded frameworks. You can install it with the following command:

$ gem install cocoapods

To integrate EvenlyWrappedLabel into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'EvenlyWrappedLabel'

Then, run the following command:

$ pod install

In case Xcode complains ("Cannot load underlying module for EvenlyWrappedLabel") go to Product and choose Clean (or simply press K).

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.

Latest podspec

{
    "name": "EvenlyWrappedLabel",
    "version": "1.3.0",
    "screenshots": "https://user-images.githubusercontent.com/2835199/31405403-f41c28ea-adcc-11e7-9555-5459ae1794d9.png",
    "summary": "EvenlyWrappedLabel vertically distributes text evenly across any number of lines, preventing orphans and text from grouping up at the top.",
    "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.n nExamples:n n1. This text:n n       This sentence has a lot of words onn       the top line.n n   Becomes:n n       This sentence has a lotn       of words on the top line.n n2. This text:n n       This sentence has a singlen       orphan.n n   Becomes:n n       This sentence hasn       a single orphan.nnFeatures:n- Works with all devices running iOS 9+.n- Uses `drawText(in:)` internally (as opposed to creating subviews), so any `UILabel` reference can be replaced with `EvenlyWrappedLabel` and Everything Will Just Worku2122.n- Works with any number of lines, any text alignment and attributed text.n- Works with autolayout and honors intrinsic sizing.n- Works with labels created in code and in Interface Builder.n- `useEveryLine` option to force shorter text to take up all available lines.n- Example app with lots of real-time configurations that lets you see the text wrap as you type.",
    "homepage": "https://github.com/StockX/EvenlyWrappedLabel",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Jeff Burt": "[email protected]"
    },
    "source": {
        "git": "https://github.com/StockX/EvenlyWrappedLabel.git",
        "tag": "1.3.0"
    },
    "social_media_url": "https://twitter.com/jeffburtjr",
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "EvenlyWrappedLabel/Classes/**/*",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This