Code Monkey home page Code Monkey logo

autolayoutbuilder's Introduction

AutoLayoutBuilder Build Status Platform Pod License

A DSL for Apple's Auto-Layout written in Swift

Examples | Installation

Why use AutoLayoutBuilder?

  • Expressive - Constraints are extremely readable and concise
  • Fast - Write fewer lines of code, and shorter ones at that
  • Safe - Invalid constraints are compiler errors
  • Flexible - Attributes are supplied as arguments, so can be varied at runtime

Examples

// Example: Left equals right
let constraints = view1[.Left] == view2[.Right]

// Example: Center X of view1, view2 and view3 equal to center X of view4
let constraints = Group(view1, view2, view3)[.CenterX] == view4[.CenterX]

// Example: Left equals left with margin
let constraints = view1[.Left] == view2[.Left] + 10

// Example: Equal X and Y centers
let constraints = view1[.Center] == view2[.Center]

// Example: Equal X centers with margin
let constraints = view1[.CenterX] == view2[.CenterX] - 10

// Example: CenterY equals Top with margin
let constraints = view1[.CenterY] == view2[.Top] - 10

// Example: Equal edges
let constraints = view1[.Edges] == view2[.Edges]

// Example: Equal edges with margin
let constraints = view1[.Edges] == view2[.Edges] - 5

// Example: Equal sizes
let constraints = view1[.Size] == view2[.Size]

// Example: Greater than or equal sizes
let constraints = view1[.Size] >= view2[.Size]

// Example: Relative sizes
let constraints = view1[.Size] == view2[.Size] * 0.5

// Example: Fixed size
let constraints = view1[.Size] == CGSize(width: 50, height: 20)

// Example: Equal widths
let constraints = view1[.Width] == view2[.Width]

// Example: Equal width and height
let constraints = view1[.Width] == view1[.Height]

// Example: Left to right layout
let constraints = .Horizontal ~ view1 | view2 | view3

// Example: Left to right layout with margins
let constraints = .Horizontal ~ view1 | 5 | view2 | 5 | view3

// Example: Leading to trailing layout with margins
let constraints = .LeadingToTrailing ~ view1 | 5 | view2 | 5 | view3

// Example: Top to bottom layout with margins
let constraints = .Vertical ~ view1 | 5 | view2 | 5 | view3

// Example: Top equals top layout guide's bottom
let constraints = view1[.Top] == viewController.layoutGuide.top[.Bottom]

// Example: Bottom equals bottom layout guide's top with margin
let constraints = view1[.Bottom] == viewController.layoutGuide.bottom[.Top] - 5

Installation

Add the following line to your Podfile

pod 'AutoLayoutBuilder'

Add the following line to your .swift files

import AutoLayoutBuilder

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.