Skip to content

Instantly share code, notes, and snippets.

@drmohundro
Created March 5, 2016 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drmohundro/44f77af356d929c0b5d9 to your computer and use it in GitHub Desktop.
Save drmohundro/44f77af356d929c0b5d9 to your computer and use it in GitHub Desktop.
Playing with Layout Constraints and VFL in Swift Playground
// playing with Xcode, Constraints and Playground
import UIKit
import XCPlayground
let hostView = UIView()
hostView.frame = CGRectMake(0, 0, 400, 200)
hostView.backgroundColor = UIColor.lightGrayColor()
XCPlaygroundPage.currentPage.liveView = hostView
let label = UILabel(frame: .zero)
label.translatesAutoresizingMaskIntoConstraints = false
label.backgroundColor = UIColor.greenColor()
label.text = "I am a label"
hostView.addSubview(label)
let views = ["label": label]
var constraints = [NSLayoutConstraint]()
constraints += NSLayoutConstraint.constraintsWithVisualFormat("H:|-25-[label]-25-|", options: [], metrics: nil, views:views)
constraints += NSLayoutConstraint.constraintsWithVisualFormat("V:|-25-[label]-25-|", options: [], metrics: nil, views:views)
NSLayoutConstraint.activateConstraints(constraints)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment