7.3k GitHub stars and counting — robb/Cartography is a Swift project TopGit is tracking across repositories on the platform. A declarative Auto Layout DSL for Swift :iphone::triangular_ruler:
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
If you end up using Cartography in production, I'd love to hear from you. You can reach me through Twitter or email.
Installation
CocoaPods
To integrate Cartography into your Xcode project using CocoaPods, specify it in your Podfile:
target '<Your Target Name>' do
pod 'Cartography', '~> 3.0'
end
Then, run the following command:
$ pod install
Usage
Call the constrain* function with your UIView or NSView instances as well
as a closure in which you declare the constraints between the different
attributes of your views:
For every view on the left hand side of an equality or inequality operator,
Cartography will automatically set its
translatesAutoresizingMaskIntoConstraints property to false.
If the view is
not controlled by you–for example if it belongs to a Apple-provided
UIViewController class–you should take appropriate care when declaring its
constraints.
Replacing constraints
You can capture multiple constraints in a group to then replace them with new
constraints at a later point.
constrain(view) { view in
view.width == 100
view.height == 100
}
let group = ConstraintGroup()
// Attach `view` to the top left corner of its superview
constrain(view, replace: group) { view in
view.top == view.superview!.top
view.left == view.superview!.left
}
/* Later */
// Move the view to the bottom right corner of its superview
constrain(view, replace: group) { view in
view.bottom == view.superview!.bottom
view.right == view.superview!.right
}
UIView.animate(withDuration: 0.5, animations: view.layoutIfNeeded)
For convenience, the constrain functions also returns ConstraintGroup
instances:
let group = constrain(button) { button in
button.width == 100
button.height == 400
}
Supported attributes
Cartography supports all built-in attributes as of iOS 8 and OS X 10.9, those are:
width
height
top
right
bottom
left
leading
trailing
centerX
centerY
baseline
as well as the iOS specific
firstBaseline
leftMargin
rightMargin
topMargin
bottomMargin
leadingMargin
trailingMargin
centerXWithinMargins
centerYWithinMargins
edgesWithinMargins
These can be further refined using the following operators: *, /, + and
-.
Additionally, it supports convenient compound attributes that allow you to
assign multiple attributes at once:
Which is equivalent to view1.top == view2.top; view2.top == view3.top. Similar
variants exist for top, rightbottom, left, leading, trailing,
centerX, centerY and baseline.
Distributing views evenly
For distributing multiple views, either horizontally or vertically, you can use
the distribute functions:
Since the ==, >=, <= and ~ emit NSLayoutConstraint instances, you can
capture their results if you need to refer to the layout constraints at a later
time:
var width: NSLayoutConstraint?
constrain(view) { view in
width = (view.width == 200 ~ 100)
}
Note that declaring compound attributes returns multiple constraints at once:
var constraints: [NSLayoutConstraint]?
constrain(view) { view in
constraints = (view.size == view.superview!.size ~ .defaultLow)
}
Documentation
Read the documentation here. For more information, see the gh-pages branch.
* Since Xcode 11 and swift 5.1 the keyword constrain conflicts with the ones used by the CommonUISDK... so, Calling the function with the module name is necessary to make it work properly
e.g.: Cartography.constrain
If you're using it with Xcode 10.3 or earlier, you can still use it as it is, without the module name alongside the function.
Versioning
For Swift 3.x: Versions <= 1.1.0
For Swift 4.x: Versions >= 2.0.0
For Swift 5.x: Versions >= 4.0.0
Support
Please, don't hesitate to file an
issue if you have questions.
About Cartography
Cartography was built by Robb Böhnke, is maintained by Orta Therox and was inspired by the excellent
FLKAutoLayout by Florian Kugler.
The most recent commit recorded on robb/Cartography was 11 months ago, based on the GitHub push timestamp. The repository has 527 forks — one of the better signals of community interest.
How many stars does robb/Cartography have?
robb/Cartography has 7.3k GitHub stars — refresh the page for the live number, or check github.com/robb/Cartography. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is robb/Cartography open source?
TopGit's metadata for robb/Cartography does not record a license. Most public repositories on GitHub ARE open source, but the exact terms vary — verify by opening the LICENSE file directly.
What is robb/Cartography?
robb/Cartography (robb/Cartography) is a Swift project on GitHub. From the project's own README: A declarative Auto Layout DSL for Swift :iphone::triangular_ruler:
Where do I read more about robb/Cartography?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/robb/Cartography is the definitive source.
Read full README in the tab above.
Still deciding about Cartography?
One click hands the question to an AI along with this page — see what it says about Cartography.