A UIView category for convenient NSLayoutConstraint creation using a simple formate language
Objective-C
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ConstraintFormat.xcodeproj
ConstraintFormat
.gitignore
README.md
UIView+ConstraintFormat.h
UIView+ConstraintFormat.m

README.md

ConstraintFormat

A UIView category for convenient NSLayoutConstraint creation using a simple format language.

This repository was created for my blog post which contains additional information.

Usage

UIView+ConstraintFormat enables the creation of NSLayoutConstraints using the format view1.attribute1 = multiplier * view2.attribute2 + constant.

NSDictionary *views = NSDictionaryOfVariableBindings(v1, v2);
[self addConstraintWithFormat:@"v1.top = v2.top" views:views];
[self addConstraintWithFormat:@"v1.bottom = v2.bottom" views:views];
[self addConstraintWithFormat:@"v1.left = v2.left" views:views];
[self addConstraintWithFormat:@"v1.right = v2.right" views:views];

The following attributes are supported:

NSDictionary *attributes = @{
    @"notAnAttribute" : @(NSLayoutAttributeNotAnAttribute),
    @"left" : @(NSLayoutAttributeLeft),
    @"right" : @(NSLayoutAttributeRight),
    @"top" : @(NSLayoutAttributeTop),
    @"bottom" : @(NSLayoutAttributeBottom),
    @"leading" : @(NSLayoutAttributeLeading),
    @"trailing" : @(NSLayoutAttributeTrailing),
    @"width" : @(NSLayoutAttributeWidth),
    @"height" : @(NSLayoutAttributeHeight),
    @"centerX" : @(NSLayoutAttributeCenterX),
    @"centerY" : @(NSLayoutAttributeCenterY),
    @"baseline" : @(NSLayoutAttributeBaseline)
};

More examples can be found in the included example project (ViewController.m).