Created
March 5, 2016 21:28
-
-
Save drmohundro/44f77af356d929c0b5d9 to your computer and use it in GitHub Desktop.
Playing with Layout Constraints and VFL in Swift Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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