explaingit

snapkit/masonry

18,167Objective-CAudience · developerComplexity · 2/5DormantLicenseSetup · easy

TLDR

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

Mindmap

mindmap
  root((repo))
    What it does
      Simplifies layout code
      Chainable constraint API
      Handles Auto Layout
    Key features
      Position and size views
      Set spacing and padding
      Constraint priorities
      Autoresizing translation
    Use cases
      Build responsive iOS apps
      Create Mac OS X interfaces
      Reduce layout boilerplate
    Tech stack
      Objective-C
      iOS SDK
      Mac OS X SDK
    Distribution
      CocoaPods
      Carthage

Things people build with this

USE CASE 1

Build responsive iOS apps that adapt to different screen sizes and orientations without writing verbose constraint code.

USE CASE 2

Create Mac OS X desktop applications with clean, readable layout definitions using chainable syntax.

USE CASE 3

Set up complex view hierarchies with spacing, padding, and alignment rules in fewer lines of code.

USE CASE 4

Define constraint priorities so some layout rules can be broken when screen space is limited.

Tech stack

Objective-CiOS SDKMac OS X SDKCocoaPodsCarthage

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose including commercial, as long as you keep the copyright notice.

In plain English

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.

Copy-paste prompts

Prompt 1
Show me how to use Masonry to make a view fill its parent with 10 points of padding on all sides.
Prompt 2
How do I center a view horizontally and vertically on its superview using Masonry's chainable syntax?
Prompt 3
Write a Masonry constraint that makes two views equal width and stacks them vertically with 20 points spacing.
Prompt 4
How do I set different constraint priorities in Masonry so some layout rules break when space is tight?
Prompt 5
Convert this verbose Auto Layout code to Masonry: [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:superview attribute:NSLayoutAttributeLeft multiplier:1.0 constant:10].
Open on GitHub → Explain another repo

Generated 2026-05-18 · Model: sonnet-4-6 · Verify against the repo before relying on details.