SnapKit/Example-iOS/demos/SimpleLayoutViewController....

97 lines
2.6 KiB
Swift
Raw Permalink Normal View History

2016-03-01 19:13:24 +08:00
//
// SimpleLayoutViewController.swift
// SnapKit
//
// Created by Spiros Gerokostas on 01/03/16.
// Copyright © 2016 SnapKit Team. All rights reserved.
//
import UIKit
class SimpleLayoutViewController: UIViewController {
var didSetupConstraints = false
2016-05-12 16:55:55 +08:00
2016-03-01 19:13:24 +08:00
let blackView: UIView = {
let view = UIView()
view.backgroundColor = .black
2016-03-01 19:13:24 +08:00
return view
}()
2016-05-12 16:55:55 +08:00
2016-03-01 19:16:44 +08:00
let redView: UIView = {
let view = UIView()
view.backgroundColor = .red
2016-03-01 19:16:44 +08:00
return view
}()
2016-05-12 16:55:55 +08:00
2016-03-01 19:20:30 +08:00
let yellowView: UIView = {
let view = UIView()
view.backgroundColor = .yellow
2016-03-01 19:20:30 +08:00
return view
}()
2016-05-12 16:55:55 +08:00
2016-03-01 19:20:30 +08:00
let blueView: UIView = {
let view = UIView()
view.backgroundColor = .blue
2016-03-01 19:20:30 +08:00
return view
}()
2016-05-12 16:55:55 +08:00
2016-03-01 19:23:33 +08:00
let greenView: UIView = {
let view = UIView()
view.backgroundColor = .green
2016-03-01 19:23:33 +08:00
return view
}()
2016-05-12 16:55:55 +08:00
2016-03-01 19:13:24 +08:00
override func viewDidLoad() {
super.viewDidLoad()
2016-05-12 16:55:55 +08:00
view.backgroundColor = UIColor.white
2016-05-12 16:55:55 +08:00
2016-03-01 19:13:24 +08:00
view.addSubview(blackView)
2016-03-01 19:16:44 +08:00
view.addSubview(redView)
2016-03-01 19:20:30 +08:00
view.addSubview(yellowView)
view.addSubview(blueView)
2016-03-01 19:23:33 +08:00
view.addSubview(greenView)
2016-05-12 16:55:55 +08:00
2016-03-01 19:13:24 +08:00
view.setNeedsUpdateConstraints()
}
override func updateViewConstraints() {
2016-05-12 16:55:55 +08:00
2016-03-01 19:13:24 +08:00
if (!didSetupConstraints) {
2016-05-12 16:55:55 +08:00
blackView.snp.makeConstraints { make in
2016-03-01 19:13:24 +08:00
make.center.equalTo(view)
make.size.equalTo(CGSize(width: 100, height: 100))
2016-05-12 16:55:55 +08:00
}
redView.snp.makeConstraints { make in
make.top.equalTo(blackView.snp.bottom).offset(20.0)
make.right.equalTo(blackView.snp.left).offset(-20.0)
make.size.equalTo(CGSize(width: 100, height: 100))
2016-05-12 16:55:55 +08:00
}
yellowView.snp.makeConstraints { make in
make.top.equalTo(blackView.snp.bottom).offset(20.0)
make.left.equalTo(blackView.snp.right).offset(20.0)
make.size.equalTo(CGSize(width: 100, height: 100))
2016-05-12 16:55:55 +08:00
}
blueView.snp.makeConstraints { make in
make.bottom.equalTo(blackView.snp.top).offset(-20.0)
make.left.equalTo(blackView.snp.right).offset(20.0)
make.size.equalTo(CGSize(width: 100, height: 100))
2016-05-12 16:55:55 +08:00
}
greenView.snp.makeConstraints { make in
make.bottom.equalTo(blackView.snp.top).offset(-20.0)
make.right.equalTo(blackView.snp.left).offset(-20.0)
make.size.equalTo(CGSize(width: 100, height: 100))
2016-05-12 16:55:55 +08:00
}
2016-03-01 19:13:24 +08:00
didSetupConstraints = true
}
2016-05-12 16:55:55 +08:00
2016-03-01 19:13:24 +08:00
super.updateViewConstraints()
}
}