Giter VIP home page Giter VIP logo

layout's Introduction

Layout

License Platform

Layout is a really small library to make it easy for you to create Auto Layout constraints in your apps. It's built on top of NSLayoutAnchor, and it includes all the type safety that comes with it. It also uses custom operators and Swift closures to make creating constraints as easy as possible:

let superview = UIView()
let subview = UIView()
superview.addSubview(subview)

// Method 1: Custom Operators
subview.layout {
  $0.top == superview.top + 16
  $0.centerX >= superview.centerX
  $0.width <= 50
  // and so on
}

// Method 2: Functions
subview.layout {
  $0.top.equals(superview.top, constant: 16)
  $0.centerX.greaterThanOrEqualTo(superView.centerX)
  $0.width.lessThanOrEqualTo(50)
  $0.height.equals(superview.height, priority: .defaultLow) // the functions let you express priority
  // and so on
}

// Helper Functions
subview.layout {
  // this will automatically negate the values for bottom and trailing
  $0.pinToEdges(superview, edgeInsets: .all(8))
}

Inspiration

This library draws a lot from SnapKit in terms of what the finished API should look like, but it's much simpler under the hood: it's under 200 LOC. In addition, my goal is to add more convenience functions to make common groups of constraints easier to build.

Installation

To use the latest version (the master branch of this repo):

pod 'Layout', :git => 'https://github.com/pranjalsatija/Layout'

To use a specific release (check the releases tab on this repo to see them all):

pod 'Layout', :git => 'https://github.com/pranjalsatija/Layout', :tag => 'x.x.x'

You should also add the -ObjC linker flag to your project's build settings so the UIView extensions that Layout has can get properly linked. Otherwise, you'll get undefined selector errors.

Pending Features

  • Multipliers
  • Aspect Ratio Constraints
  • More Convenience Functions?
  • Tests

Author

pranjalsatija, [email protected]

License

Layout is available under the MIT license. See the LICENSE file for more info.

layout's People

Contributors

pranjalsatija avatar

Watchers

James Cloos avatar  avatar

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.