GithubHelp home page GithubHelp logo

joeypatino / pinnable Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 58 KB

Simple NSLayoutConstraint creation and management

License: MIT License

Ruby 3.31% Swift 96.69%
nslayoutconstraints autolayout uiview autolayout-constraints

pinnable's Introduction

Pinnable


NSLayoutConstraints simplified

Quickly setup constraints with just a few lines of code

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

let topPin = subview.pin(edge: .top, toView: view)
let bottomPin = subview.pin(edge: .bottom, toView: view)
let leadingPin = subview.pin(edge: .leading, toView: view)
let trailingPin = subview.pin(edge: .trailing, toView: view)

Easily configure percentage based constraints to allow relative positioning of UIView's

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

// pin the subviews width to 50% of the parent view and add a constraint for the aspect ratio
let widthPin = subview.pin(dimension: .width, to: 0.5, relativeTo: view, aspectRatio: 16.0/9.0)
    
// pin the bottom edge of the subview to the bottom edge of the view. The margin will be 15% of the 
// height of the view
let bottomPin = subview.pin(edge: .bottom, toView: view, toAnchor: .bottom, margin: 0.15, relative:true)
    
// pin the subview to be centered on the x axis of the view
let axisPin = subview.pin(toAxis: .x, inView: view, offset:0)

Using the Pin object you can update the properties of the constraint at any time, i.e disable/enable, update the constant, or even the multiplier

bottomPin.isActive = false

OR

axisPin.set(value:100)

OR

bottomPin.set(value: 0.5)

Written in Swift, enjoy ;-)

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.