Skip to content

Instantly share code, notes, and snippets.

@3lvis
Last active August 29, 2016 10:13
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 3lvis/6478a2f561169aece5de93bf2344379f to your computer and use it in GitHub Desktop.
Save 3lvis/6478a2f561169aece5de93bf2344379f to your computer and use it in GitHub Desktop.
import UIKit
import XCPlayground
let containerWidth = CGFloat(320)
let containerHeight = CGFloat(568)
//***************************
//***************************
//****** Basic set up *******
//***************************
//***************************
let window = UIView()
window.translatesAutoresizingMaskIntoConstraints = false
window.backgroundColor = .whiteColor()
XCPlaygroundPage.currentPage.liveView = window
let firstView = UIView()
firstView.translatesAutoresizingMaskIntoConstraints = false
firstView.backgroundColor = .blackColor()
window.addSubview(firstView)
let secondView = UIView()
secondView.translatesAutoresizingMaskIntoConstraints = false
secondView.backgroundColor = .blackColor()
window.addSubview(secondView)
//***************************
//***************************
//****** Manual Layout ******
//***************************
//***************************
/*let horizontalMargin = 20
let width = containerWidth - (horizontalMargin * 2)
let height = 80
var firstViewFrame: CGRect {
let topMargin = 20
return CGRect(x: horizontalMargin, y: topMargin, width: width, height: height)
}
firstView.frame = firstViewFrame
var secondViewFrame: CGRect {
let topMargin = Int(firstView.frame.maxY + 8)
return CGRect(x: horizontalMargin, y: topMargin, width: width, height: height)
}
secondView.frame = secondViewFrame*/
//***************************
//***************************
//****** Auto Layout ********
//***************************
//***************************
window.widthAnchor.constraintEqualToConstant(containerWidth).active = true
window.heightAnchor.constraintEqualToConstant(containerHeight).active = true
let margin = CGFloat(20)
firstView.topAnchor.constraintEqualToAnchor(window.topAnchor, constant: margin).active = true
firstView.widthAnchor.constraintEqualToConstant(120).active = true
firstView.heightAnchor.constraintEqualToConstant(80).active = true
firstView.centerXAnchor.constraintEqualToAnchor(window.centerXAnchor).active = true
secondView.topAnchor.constraintEqualToAnchor(firstView.bottomAnchor, constant: margin).active = true
secondView.widthAnchor.constraintEqualToConstant(120).active = true
secondView.heightAnchor.constraintEqualToConstant(80).active = true
secondView.centerXAnchor.constraintEqualToAnchor(window.centerXAnchor).active = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment