An autolayout library for the damn fine citizens of San Diego.

Related tags

Layout ios autolayout
Overview

Anchorman

BuddyBuild Pod Version Swift Version License MIT Plaform

Do you think autolayout has to be hard?

That doesn't make any sense

Nah. NSLayoutAnchor is pretty neat! But it's still a bit tedious of an API. Try writing .translatesAutoresizingMaskIntoConstraints = false and .isActive = true 10 times over. But we can make it a bit easier with a very thin layer of abstraction.

I don't know what we're yelling about!

Let's start off with a vocabulary lesson.


UIView and UILayoutGuide are Anchorable. You can pin one to the other, in any combination you like, as long as it generates valid NSLayoutConstraints.

How's it work?


I am a cool developer, making a cool app. It has so many views. I want to pin my view to it's superview.

self.backgroundView.pinToSuperview()

That was easy, but I don't want to pin to a superview anymore, I want to pin to another view.

self.messageLabel.pin(to: self.backgroundView)

Ah, ok. Easy enough… How about pinning my label to the left and right side of it's superview… and with insets… and center it in my view.

self.titleLabel.pinToSuperview([ .leading(10.0), .trailing(10.0), .centerY ])

Whoa, that was neat! You can specify a group of edges you want to pin to, and their offsets. Swift enums are the best!

That escalated quickly

And of course, you can pick one edge to pin to another edge.

self.footerLabel.pin(edge: .bottom, toEdge: .bottom, of: self.view.safeAreaLayoutGuide, constant: 10.0)

Last but not least, set constant values for your constraints. For width, height, or both.

self.footerLabel.set(size: .width(44.0) ])
self.titleLabel.set(size: [ .width(44.0), .height(44.0) ])

I lied, there's a bit more. Anchorman includes a couple of goodies to make your life easier between iOS 10 and iOS 11.

var backwardsCompatibleSafeAreaLayoutGuide: UILayoutGuide 
var backwardsCompatibleSafeAreaInsets: UIEdgeInsets 

These will use safeAreaLayoutGuide and safeAreaInsets on iOS 11, and layoutMarginsGuide and layoutMargins on iOS 10, so you can avoid a whole bunch of if #available conditions.

Installation

Anchorman supports Swift 4 with the latest versions. If you're looking for Swift 3 support, use version 2.0

You can use CocoaPods to install Anchorman by adding it to your Podfile:

platform :ios, '8.0'
use_frameworks!

pod 'Anchorman'

Or Carthage

github "mergesort/Anchorman"

Or install it the old fashioned way by downloading Anchorman.swift and dropping it in your project.

About me

I'm Ron Burgundy

Hi, I'm Joe! @mergesort everywhere on the web, but especially on Twitter.

License

See the license for more information about how you can use Anchorman. I promise it's not GPL, because I am not "that guy".

Fin

Hopefully Anchorman is your cup of tea, it's the kind of autolayout library I'd want to use. And with that, good night San Diego.

Stay Classy San Diego

You might also like...
A bit of steroids for AutoLayout, powered by Swift.

AutoLayoutPlus AutoLayoutPlus is a Swift library consisting in a set of extensions to help dealing with Auto Layout programatically. With AutoLayoutPl

Tiny Swift DSL for Autolayout

SwiftAutoLayout SwiftAutoLayout is a tiny DSL for Autolayout intended to provide a more declarative way to express layout constraints. Here's a quick

Minimal AutoLayout convenience layer. Program constraints succinctly.

MiniLayout Minimal AutoLayout convenience layer. Program constraints succinctly. Usage Put label over textField // using MiniLayout: view.constrain(la

A AutoLayout Utility for iOS

QLayout is an Utility to make Auto Layout easy on iOS. Contents Requirements Installation Usage Credits License Requirements iOS 8.0+ Swift 3.0+ Insta

AutoLayout Micro DSL SPM from Chris Eidhof's article

EasyAutoLayout Intro EasyAutoLayout is a small framework built using the ideas presented in the article called Autolayout Micro DSL by Chris Eidhof. I

FrameLayoutKit is a super fast and easy to use autolayout kit
FrameLayoutKit is a super fast and easy to use autolayout kit

FrameLayoutKit FrameLayout is a super fast and easy to use layout library for iOS and tvOS. For Objective-C version: NKFrameLayoutKit (Deprecated, not

LayoutLoopHunter - Runtime-based setup for tracking autolayout feedback loops
LayoutLoopHunter - Runtime-based setup for tracking autolayout feedback loops

LayoutLoopHunter The library helps to catch the OOMs caused by Autolayout Feedback Loop by replicating the behavior of UIViewLayoutFeedbackLoopDebuggi

An extension that simplifies the work with Swift AutoLayout by writing cleaner, more natural and easy-reading code.

Installation For now you're able to clone repo in your project or download ZIP folder manually. git clone https://github.com/votehserxam/AutoLayout.gi

 BrickKit is a delightful layout library for iOS and tvOS. It is written entirely in Swift!
BrickKit is a delightful layout library for iOS and tvOS. It is written entirely in Swift!

BrickKit is a delightful layout library for iOS and tvOS. It is written entirely in Swift! Deprecated BrickKit is being phased out at Wayfair, and the

Comments
  • Better README.md

    Better README.md

    Hey @mergesort, your library is really interesting.

    The only problem I found was the README.md, which lacks a little bit of information I created this iOS Open source Readme Template so you can take a look on how to better organize. If you want, I can help you to organize the lib.

    What are your thoughts?

    opened by lfarah 9
  • Add Multiplier Support

    Add Multiplier Support

    Currently the library supports constants, but doesn't support multipliers as a way to express a relation.

    I'd propose being able to pass in the multiplier as a parameter, when pinning an edge or view to another as the implementation.

    opened by mergesort 1
  • Add less than, greater than, and equal to relations

    Add less than, greater than, and equal to relations

    Currently the library only supports relations where one anchor is made to be equal to another. That's not what we may want in every scenario, so simply enough, there should be that.

    I'd propose being able to pass in the relation as a parameter, when pinning an edge or view to another as the implementation.

    opened by mergesort 1
  • pinToSuperview(_:relation:activate:) ignores relation parameter

    pinToSuperview(_:relation:activate:) ignores relation parameter

    Give the following call:

    view.pinToSuperview([.leading(20), .trailing(-20)], relation: .lessThanOrEqual)

    Anchorman will ignore the .lessThanOrEqual and use .equal instead. It's not propagating the property onto the pinToView() function, so instead its using the default .equal.

    opened by Killectro 0
Releases(3.2.0)
  • 3.2.0(Jan 19, 2020)

  • 3.1(Dec 24, 2018)

  • 3.0(Sep 19, 2017)

    • The underlying framework is completely rewritten. If you find any bugs, please report them. 🐛

    • This version is written in and supports Swift 4. If you need to use Swift 3, use version 2.0 of Anchorman instead.


    New Features

    • Anchorman now supports UILayoutGuide along with UIView constraints.

    • Adding support for .left and .right EdgeAnchors.


    ⚠️ Breaking changes ⚠️

    • Removed func translateAutoresizingMasks(on: Bool)

    • Removed static func activateAllConstraints(constraints: [[NSLayoutConstraint]])

    • Removed static func deactivateAllConstraints(constraints: [[NSLayoutConstraint]])

    • For functions that had a parameter activate: Bool, it has now been renamed isActive: Bool.

    API changes for pinning

    ~~func pinToSuperview(_ edges: [EdgeAnchor], relation: NSLayoutRelation, activate: Bool) -> [NSLayoutConstraint]~~

    func pinToSuperview(_ edges: [EdgeAnchor], relation: NSLayoutRelation, isActive: Bool) -> [NSLayoutConstraint]


    ~~func pin(toView view: UIView, edges: [EdgeAnchor], relation: NSLayoutRelation, activate: Bool) -> [NSLayoutConstraint]~~

    func pin(to view: UIView, edges: [EdgeAnchor], relation: NSLayoutRelation, isActive: Bool) -> [NSLayoutConstraint]


    ~~func pin(edge: EdgeAnchor, toEdge: EdgeAnchor, ofView view: UIView, relation: NSLayoutRelation, constant: CGFloat, priority: UILayoutPriority, activate: Bool) -> NSLayoutConstraint~~

    func pin(edge: EdgeAnchor, toEdge: EdgeAnchor, of view: UIView, relation: NSLayoutRelation = .equal, constant: CGFloat, priority: UILayoutPriority, isActive: Bool) -> NSLayoutConstraint


    ~~func set(size sizeAnchor: SizeAnchor, relation: NSLayoutRelation, activate: Bool) -> NSLayoutConstraint~~

    func set(size sizeAnchor: SizeAnchor, relation: NSLayoutRelation, isActive: Bool) -> NSLayoutConstraint


    ~~func set(size sizeAnchors: [SizeAnchor] = [ SizeAnchor.width, SizeAnchor.height ], relation: NSLayoutRelation, activate: Bool) -> [NSLayoutConstraint]~~

    func set(size sizeAnchors: [SizeAnchor] = [ SizeAnchor.width, SizeAnchor.height ], relation: NSLayoutRelation, isActive: Bool) -> [NSLayoutConstraint]


    ~~func set(relativeSize sizeAnchor: SizeAnchor, toSizeAnchor: SizeAnchor, ofView view: UIView, multiplier: CGFloat, constant: CGFloat, relation: NSLayoutRelation, activate: Bool) -> NSLayoutConstraint~~

    func set(relativeSize sizeAnchor: SizeAnchor, toSizeAnchor: SizeAnchor, ofAnchorable anchorable: Anchorable, multiplier: CGFloat, constant: CGFloat, relation: NSLayoutRelation, isActive: Bool)

    Source code(tar.gz)
    Source code(zip)
  • 2.0(Dec 3, 2016)

    This release is a completely breaking change to the API.

    • The library is now compatible with Swift 3 only. The previous release will continue to work with Swift 2.2.

    Source code(tar.gz)
    Source code(zip)
  • 1.2.1(Oct 4, 2016)

    • Fixes a bug that set self.translatesAutoresizingMaskIntoConstraints = false onto the view being pinned to, which is bad when the view is self.view.

    Source code(tar.gz)
    Source code(zip)
  • 1.2(Oct 4, 2016)

    This version supports Swift 3, but not 2.2 or 2.3.

    Your code that compiled for Swift 2.2 or 2.3 should not change, and remains compatible. A future update will add Swift 3 naming conventions into the code.

    • Brings the library support to 3.0. • Code clean up.

    Source code(tar.gz)
    Source code(zip)
  • 1.1.2(Jul 16, 2016)

  • 1.1.1(Jul 6, 2016)

  • 1.1(Jun 25, 2016)

    setSize now overloads allowing to take in either a SizeAnchor, or [SizeAnchor], depending on the parameter passed in, returning NSLayoutConstraint and [NSLayoutConstraint] respectively.

    • Breaking change: .allEdges has been renamed to .allSides, since those semantics are representative of pinning a view's .leading, .trailing, .top, and .bottom edges.

    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Jun 3, 2016)

Owner
Joe Fabisevich
iOS developer Working hard to make @Twitter a little healthier every day, no one said it would be easy. I am the friend you made along the way. 🧡
Joe Fabisevich
SwiftLayout - View hierarchy and autolayout DSL library

SwiftLayout view hierarchy and autolayout DSL library goal 뷰의 계층구조와 constraint 관

iOS Swifty Krew 104 Dec 28, 2022
Write concise Autolayout code

Winner of Hacking with Swift Recommended award You + Stevia = ?? ?? Write concise, readable layouts ?? Reduce your maintenance time ?? Compose your st

Fresh 3.3k Jan 6, 2023
📱AutoLayout can be set differently for each device

DeviceLayout DeviceLayout is a Swift framework that lets you set Auto Layout constraints's differently for each device Using only IBInspector of Xcode

Cruz 171 Oct 11, 2022
An easier and faster way to code Autolayout

EZAnchor 中文介绍 An easier way to code Autolayout Are you annoyed of coding .active = true while using Autolayout Anchors over and over again? Are you an

Alex.Liu 25 Feb 20, 2022
MisterFusion is Swift DSL for AutoLayout. It is the extremely clear, but concise syntax, in addition, can be used in both Swift and Objective-C. Support Safe Area and Size Class.

MisterFusion MisterFusion makes more easier to use AutoLayout in Swift & Objective-C code. Features Simple And Concise Syntax Use in Swift and Objecti

Taiki Suzuki 316 Nov 17, 2022
The fast path to autolayout views in code

NorthLayout The fast path to autolayout views in code Talks https://speakerdeck.com/banjun/auto-layout-with-an-extended-visual-format-language at AltC

banjun 36 Jul 15, 2022
A Swift Autolayout DSL for iOS & OS X

SnapKit is a DSL to make Auto Layout easy on both iOS and OS X. ⚠️ To use with Swift 4.x please ensure you are using >= 4.0.0 ⚠️ ⚠️ To use with Swift

null 19.1k Jan 2, 2023
🏗 MondrianLayout - describing structured layout for AutoLayout

?? A DSL based layout builder for AutoLayout

Muukii 155 Dec 10, 2022
This "Calculator" application is a simple one screen design of calculator screen i have made this single screen design application just to practice AutoLayout concepts.

Calculator Layout This "Calculator" application is a simple one screen design of calculator screen i have made this single screen design application j

Chetan Parate 1 Oct 29, 2021
Harness the power of AutoLayout NSLayoutConstraints with a simplified, chainable and expressive syntax. Supports iOS and OSX Auto Layout

Masonry Masonry is still actively maintained, we are committed to fixing bugs and merging good quality PRs from the wider community. However if you're

null 18k Jan 5, 2023