Skip to content

Instantly share code, notes, and snippets.

@pixelrevision
Created December 6, 2016 18:43
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 pixelrevision/6482661045002868cf0ba3ad8ec264a1 to your computer and use it in GitHub Desktop.
Save pixelrevision/6482661045002868cf0ba3ad8ec264a1 to your computer and use it in GitHub Desktop.
import UIKit
import PlaygroundSupport
class SampleController: UIViewController {
init() {
super.init(nibName: nil, bundle: nil)
title = "Sample View"
view = UIView()
view.backgroundColor = UIColor.green
let topView = UIView()
topView.translatesAutoresizingMaskIntoConstraints = false
topView.backgroundColor = UIColor.red
view.addSubview(topView)
view.addConstraints([
NSLayoutConstraint(item: topView, attribute: .top, relatedBy: .equal, toItem: topLayoutGuide, attribute: .bottom, multiplier: 1.0, constant: 0.0),
NSLayoutConstraint(item: topView, attribute: .left, relatedBy: .equal, toItem: view, attribute: .left, multiplier: 1.0, constant: 0.0),
NSLayoutConstraint(item: topView, attribute: .right, relatedBy: .equal, toItem: view, attribute: .right, multiplier: 1.0, constant: 0.0),
NSLayoutConstraint(item: topView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 40.0)
])
let bottomView = UIView()
bottomView.translatesAutoresizingMaskIntoConstraints = false
bottomView.backgroundColor = UIColor.blue
view.addSubview(bottomView)
view.addConstraints([
NSLayoutConstraint(item: bottomView, attribute: .top, relatedBy: .equal, toItem: topView, attribute: .bottom, multiplier: 1.0, constant: 0.0),
NSLayoutConstraint(item: bottomView, attribute: .left, relatedBy: .equal, toItem: view, attribute: .left, multiplier: 1.0, constant: 0.0),
NSLayoutConstraint(item: bottomView, attribute: .right, relatedBy: .equal, toItem: view, attribute: .right, multiplier: 1.0, constant: 0.0),
NSLayoutConstraint(item: bottomView, attribute: .bottom, relatedBy: .equal, toItem: bottomLayoutGuide, attribute: .top, multiplier: 1.0, constant: 0.0)
])
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
let navigationController = UINavigationController()
navigationController.viewControllers = [SampleController()]
PlaygroundPage.current.liveView = navigationController.view
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment