gitmyhub

Masonry

Objective-C ★ 18k updated 3y ago

Harness the power of AutoLayout NSLayoutConstraints with a simplified, chainable and expressive syntax. Supports iOS and OSX Auto Layout

Masonry simplifies iOS layout code by replacing verbose Auto Layout constraints with a clean, chainable syntax for positioning UI elements.

Objective-CiOS SDKMac OS X SDKCocoaPodsCarthagesetup: easycomplexity 2/5

Masonry is an Objective-C library for iOS and Mac OS X that simplifies the way developers define layout rules (called Auto Layout constraints) for user interface elements. Auto Layout is Apple's system for positioning views on screen in a way that adapts to different screen sizes and orientations. Normally, writing these constraints in code is very verbose — a single simple rule like "this view should fill its parent with 10 points of padding on each side" requires many lines of repetitive, hard-to-read code.

Masonry provides a cleaner, chainable syntax for the same thing. Instead of constructing constraint objects manually, you use a block-based API where you describe relationships in a natural way, such as "make this view's edges equal to its superview's edges with insets." The library automatically attaches the constraints to the right views and handles the usual boilerplate of disabling autoresizing translation. It supports all standard layout attributes: position, size, centering, and spacing, as well as setting priorities so that some constraints can be broken when space is tight.

The project recommends its Swift-language counterpart, SnapKit, for projects written in Swift, since Swift offers better type safety. Masonry itself remains actively maintained for Objective-C projects. It is available via CocoaPods and Carthage, the common iOS dependency managers.

Where it fits