BCBalancedMultilineLabel 0.3.0

BCBalancedMultilineLabel 0.3.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Nov 2015

Maintained by Brian Croom.




Have you ever placed a label in your view controller, gave it some nice copy to display, ran your app and then cringed because everything fit on one line except for one or two lone words?

Regular Label

Your first reaction to this might be to run over to Interface Builder and adjust the label's width so that the lines are more even. But what happens when you need to show different text? Or you localize your app? Or adopt dynamic type? In these situations, keeping things working becomes a maintenance nightmare.

BCBalancedMultilineLabel will take care of adjusting the line breaks such that each line is as close to the same length as possible, making your text look beautiful. It supports left, right, and center alignments equally well.

Balanced Label Balanced Label Right Aligned

It also simplifies handling a couple of other UILabel properties:

  • numberOfLines is defaulted to 0, as this label is intended to be used for content that wraps to multiple lines.
  • preferredMaxLayoutWidth is automatically kept in sync with the label's frame width, which helps ensure that the label sizes itself as intended when used with autolayout.

Usage

Using BCBalancedMultilineLabel in your project couldn't be easier! Just change the class of your label in Interface Builder or in your Objective-C or Swift code to be BCBalancedMultilineLabel instead of UILabel, and you're done!

UILabel *label = [[BCBalancedMultilineLabel alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
label.text = @"My cool app";
[self.view addSubview:label];
let label = BCBalancedMultilineLabel(frame: CGRect(x: 0, y: 0, width: 300, height: 50))
label.text = "My cool app"
view.addSubview(label)

To run the example project, clone the repo, and run pod install from the Example directory first.

Example App

Installation

Author

Brian Croom, [email protected]

License

BCBalancedMultilineLabel is available under the MIT license. See the LICENSE file for more info.