|
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 |