Last active
August 3, 2017 16:31
-
-
Save fdstevex/af1c0a13a5e6ce696bf0 to your computer and use it in GitHub Desktop.
Auto layout in 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
// Auto layout in a Swift Playground (for iOS). | |
import UIKit | |
var v = UIView() | |
v.frame = CGRectMake(0, 0, 200, 200) | |
var b1 = UIButton() | |
b1.setTitle("Click Me", forState:UIControlState.Normal) | |
b1.setTitleColor(UIColor.blueColor(), forState: UIControlState.Normal) | |
b1.setTranslatesAutoresizingMaskIntoConstraints(false) | |
v.addSubview(b1) | |
var b2 = UIButton() | |
b2.setTitle("Click Me Too", forState:UIControlState.Normal) | |
b2.setTitleColor(UIColor.blueColor(), forState: UIControlState.Normal) | |
b2.setTranslatesAutoresizingMaskIntoConstraints(false) | |
v.addSubview(b2) | |
var views = Dictionary<String, UIView>() | |
views["b1"] = b1 | |
views["b2"] = b2 | |
v.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-[b1]-|", options: nil, metrics: nil, views: views)) | |
v.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-[b2]-|", options: nil, metrics: nil, views: views)) | |
v.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-[b1]-[b2]", options: nil, metrics: nil, views: views)) | |
v.layoutIfNeeded() | |
b1.frame | |
b2.frame | |
v.frame | |
v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can set the Platform (iOS or OS X) in the file explorer: View -> Utilities -> Show File Explorer