GithubHelp home page GithubHelp logo

sundarsan / anchorage Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rightpoint/anchorage

0.0 1.0 0.0 6 KB

A collection of operators and utilities that simplify iOS layout code.

License: MIT License

Ruby 4.24% Swift 95.76%

anchorage's Introduction

Anchorage

Version

A collection of intuitive operators and utilities that simplify iOS layout code. Anchorage is built directly on top of the NSLayoutAnchor API, so fully supports UILayoutGuide. Each equation or inequality acts on one or more NSLayoutAnchors, and returns active NSLayoutConstraints.

Spacing

// Pin the button to at least 12 pts from the edges of its container view, and center it
button.leftAnchor    >= container.leftAnchor + 12
button.centerXAnchor == container.centerXAnchor
button.centerYAnchor == container.centerYAnchor
// Pin all edges of a view to its container
imageView.edgeAnchors == container.edgeAnchors
// Pin only leading and trailing edges of a view to be within its container
// Note that in this case the >= is interpreted to mean "leading >=, trailing <="
imageView.horizontalAnchors >= container.horizontalAnchors
// Pin only top and bottom edges of a view to be within its container
// Note that in this case the >= is interpreted to mean "top >=, bottom <="
imageView.verticalAnchors >= container.verticalAnchors

Sizing

// Constrain a view's width to be at most 100 pts
view.widthAnchor <= 100

// Constrain two views to be the same size
view1.widthAnchor  == view2.widthAnchor
view1.heightAnchor == view2.heightAnchor

// Constrain view to 4:3 aspect ratio
view.widthAnchor == 4 * view.heightAnchor / 3

Priority

Priority of NSLayoutConstraints must be set before they are active. The ~ is used to specify priority of the constraint resulting from an equation:

// Align view 20 points from the center of its superview, with low priority
view.centerXAnchor == (view.superview.centerXAnchor + 20) ~ UILayoutPriorityDefaultLow

UIKit provides UILayoutPriorityDefaultLow, UILayoutPriorityDefaultHigh, and UILayoutPriorityRequired constants, but you may specify any Float for a priority value.

anchorage's People

Contributors

jvisenti avatar

Watchers

James Cloos 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.