Skip to content

Masonry

A lightweight Objective-C wrapper that makes Auto Layout constraints shorter and easier to read.

Stars
18.1k
Forks
3.1k
Licence
MIT
Language
Objective-C
Last update
3.6 years ago
Type
Library

No commits in over a year — check for forks or alternatives before adopting.

What it is

Masonry is a layout library for iOS and macOS apps. Auto Layout normally requires long, repetitive code to position views, and Masonry wraps it in a chainable syntax such as make.edges.equalTo(superview). The README says it produces more concise and readable layout code than raw NSLayoutConstraint calls, and that it adds constraints to the right view and turns off translatesAutoresizingMaskIntoConstraints for you.

  • Pinning a view to its superview with a fixed inset on every side using make.edges.equalTo(superview).with.insets(padding)
  • Setting minimum or maximum width and height with greaterThanOrEqualTo and lessThanOrEqualTo
  • Assigning constraint priorities such as priorityLow or priority(600)
  • Making a view's size or center match another view with make.size or make.center

Great for

  • iOS or macOS developers writing Objective-C projects that use Auto Layout in code
  • Teams maintaining existing Masonry-based code
  • Developers who want shorter constraint code without Visual Format Language strings

Not ideal for

  • Swift-only projects: the README recommends SnapKit instead for better type safety and a simpler API
  • People who build layouts in Interface Builder or storyboards, since the library is aimed at code-based constraints
  • Non-developers, because the code examples assume familiarity with Objective-C and Auto Layout
Step-by-step guide: how to use MasonryInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: CocoaPods (the README mentions pod install for the examples project)

    Run CocoaPods install for the examples project

    pod install
  2. 2

    Run it

    • Add Masonry to your project with your preferred dependency manager (the README excerpt does not show the exact Podfile line)
    • Import Masonry in the view controller or view file where you lay out views
    • Call view.mas_makeConstraints with a MASConstraintMaker block and describe the constraints
    • Open the Masonry iOS Examples project in the Masonry workspace to see working code
  3. 3

    Get the most out of it

    • Define MAS_SHORTHAND_GLOBALS before importing Masonry to use unprefixed macros like equalTo(@10)
    • Use mas_equalTo with primitives and structs such as CGSizeMake or UIEdgeInsetsMake for constant values
    • Chain .with.priority(...) or priorityLow/priorityHigh to tune how strongly a constraint applies
    • Use edges, size and center composite constraints to write several constraints in one line

Downloads

Strengths

  • Constraint code is considerably shorter than the equivalent NSLayoutConstraint code, per the README's examples
  • Automatically adds constraints to the appropriate view and sets translatesAutoresizingMaskIntoConstraints
  • Supports iOS and macOS Auto Layout with a mix of view attributes, numbers, structs and arrays

Trade-offs

  • The README recommends SnapKit for new Swift projects, so this is best suited to Objective-C codebases
  • Latest release is v1.1.0 and the last push shown is from April 2023, so update activity may be limited
  • The README describes the project as still maintained, but the README excerpt does not spell out a support timeline

How it compares

ProjectStarsTypeLevelUpdatedBest for
Masonry (this)18.1kLibraryintermediate3.6 years agoiOS or macOS developers writing Objective-C projects that use Auto Layout in code
SnapKit20.3kLibraryintermediate4 months agoSwift developers building UIKit or AppKit interfaces in code rather than Interface Builder

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.