Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.