To integrate Paralayout into your Xcode project using Carthage, specify it in your Cartfile:

github "Square/Paralayout"

Run carthage to build the framework and drag the built Paralayout.framework into your Xcode project.

Submodules

Or, manually check out the submodule with git submodule add git@github.com:Square/Paralayout.git, drag Paralayout.xcodeproj to your workspace, and add Paralayout as a build dependency.

Usage

Paralayout is a set of à la carte utilities, of which you can use as much or as little functionality as you like.

UILabel Subclass: Label

The Label class makes text look its best, and takes less cumbersome code to configure:

Style text without directly interacting with NSAttributedString or NSParagraphStyle (any more than you want to)

Get "compact" line wrapping that makes it unnecessary to introduce artificial line breaks into your copy

Hyperlinks are tappable (no need to use a UITextView)

UIView Subclass: Hairline

A Hairline will size itself correctly on any screen resolution, and provides conveniences for positioning within its superview.

/// Put a line at the bottom of the view, inset 20 points on each side.let separator = Hairline.new(in: view, at: .maxYEdge, inset: 20)

New Value Type: Interpolation

Get the math right for multi-phase layout transitions and animations without tearing your hair out! Under the hood it’s simply a value between 0 and 1, but it makes computing that value, and deriving a new value from it, effortless.

CGGeometry Extensions

These extensions provide numerous conveniences for computing rectangles and snapping coordinates to pixel dimensions. The ScaleFactor protocol encapsulates the latter, allowing a view to provide the context necessary to align its subviews to pixels. One benefit of this approach is that unit tests can cover both 2x and 3x scale factors regardless of the simulator used to run the test.

UIDevice Extensions

In practice, designers adjust margins and text sizes for specific device sizes, not abstract screen dimensions. It may be simplest, for example, to just hide a particular UI element on 3.5" iPhones only, rather than build complex sizing/layout logic that triggers the behavior change at a threshold associated with a small screen.

UIFont Extensions

The extra space within a label above the "cap height" and below the "baseline" of its font is deterministic but non-obvious, especially at different scale factors. The simple LabelCapInsets value type encapsulates that logic.

UIView Alignment Extensions

The core positioning function (and its numerous derived convenience functions) allows one view to be positioned relative to another view:

Debugging

Fixing layout issues is as simple as using the Xcode debugger. Remember that on a 2x device, view frame coordinates will be snapped to half-point boundaries (x.0 and x.5 only), while on 3x devices they are on 1/3-point boundaries (x.0, x.333, and x.667). The offsets used for view alignment do not need to be rounded (and generally shouldn’t be, to avoid accumulating rounding error), but view sizes should be.

Requirements

Xcode 8 / Swift 3.0

iOS 9.0 or later

Contributing

We’re glad you’re interested in Paralayout, and we’d love to see where you take it. Please read our contributing guidelines prior to submitting a pull request.