mirror of https://github.com/SnapKit/SnapKit
Update example project for Swift 3 (#376)
This commit is contained in:
parent
3ce0d32bce
commit
32cd509939
|
@ -13,19 +13,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
|
|
||||||
var window: UIWindow?
|
var window: UIWindow?
|
||||||
|
|
||||||
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
|
||||||
|
|
||||||
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
|
self.window = UIWindow(frame: UIScreen.main.bounds)
|
||||||
|
|
||||||
let listViewController:ListViewController = ListViewController()
|
let listViewController:ListViewController = ListViewController()
|
||||||
let navigationController:UINavigationController = UINavigationController(rootViewController: listViewController);
|
let navigationController:UINavigationController = UINavigationController(rootViewController: listViewController);
|
||||||
|
|
||||||
self.window!.rootViewController = navigationController;
|
self.window!.rootViewController = navigationController;
|
||||||
|
|
||||||
self.window!.backgroundColor = UIColor.whiteColor()
|
self.window!.backgroundColor = UIColor.white
|
||||||
self.window!.makeKeyAndVisible()
|
self.window!.makeKeyAndVisible()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,35 +13,34 @@ class ListViewController: UITableViewController {
|
||||||
|
|
||||||
let kCellIdentifier = "CellIdentifier"
|
let kCellIdentifier = "CellIdentifier"
|
||||||
let demos = ["Simple Layout", "Basic UIScrollView"]
|
let demos = ["Simple Layout", "Basic UIScrollView"]
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
self.title = "SnapKit iOS Demos"
|
self.title = "SnapKit iOS Demos"
|
||||||
|
|
||||||
self.tableView?.registerClass(UITableViewCell.self, forCellReuseIdentifier: kCellIdentifier)
|
self.tableView?.register(UITableViewCell.self, forCellReuseIdentifier: kCellIdentifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
let cell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier)! as UITableViewCell
|
return demos.count
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
|
let cell = tableView.dequeueReusableCell(withIdentifier: kCellIdentifier)! as UITableViewCell
|
||||||
|
|
||||||
cell.textLabel?.text = demos[indexPath.row]
|
cell.textLabel?.text = demos[indexPath.row]
|
||||||
|
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
return demos.count
|
|
||||||
}
|
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
|
|
||||||
if indexPath.row == 0 {
|
if indexPath.row == 0 {
|
||||||
let viewController = SimpleLayoutViewController()
|
let viewController = SimpleLayoutViewController()
|
||||||
navigationController?.pushViewController(viewController, animated: true)
|
navigationController?.pushViewController(viewController, animated: true)
|
||||||
} else if indexPath.row == 1 {
|
} else if indexPath.row == 1 {
|
||||||
let viewController = BasicUIScrollViewController()
|
let viewController = ViewController()
|
||||||
navigationController?.pushViewController(viewController, animated: true)
|
navigationController?.pushViewController(viewController, animated: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class BasicUIScrollViewController: UIViewController {
|
class BasicUIScrollViewController: UIViewController {
|
||||||
|
|
||||||
var didSetupConstraints = false
|
var didSetupConstraints = false
|
||||||
|
|
||||||
let scrollView = UIScrollView()
|
let scrollView = UIScrollView()
|
||||||
|
@ -17,22 +17,22 @@ class BasicUIScrollViewController: UIViewController {
|
||||||
|
|
||||||
let label: UILabel = {
|
let label: UILabel = {
|
||||||
let label = UILabel()
|
let label = UILabel()
|
||||||
label.backgroundColor = .blueColor()
|
label.backgroundColor = .blue
|
||||||
label.numberOfLines = 0
|
label.numberOfLines = 0
|
||||||
label.lineBreakMode = .ByClipping
|
label.lineBreakMode = .byClipping
|
||||||
label.textColor = .whiteColor()
|
label.textColor = .white
|
||||||
label.text = NSLocalizedString("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", comment: "")
|
label.text = NSLocalizedString("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", comment: "")
|
||||||
return label
|
return label
|
||||||
}()
|
}()
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
view.backgroundColor = UIColor.whiteColor()
|
view.backgroundColor = UIColor.white
|
||||||
|
|
||||||
view.addSubview(scrollView)
|
view.addSubview(scrollView)
|
||||||
|
|
||||||
contentView.backgroundColor = UIColor.lightGrayColor()
|
contentView.backgroundColor = UIColor.lightGray
|
||||||
scrollView.addSubview(contentView)
|
scrollView.addSubview(contentView)
|
||||||
contentView.addSubview(label)
|
contentView.addSubview(label)
|
||||||
|
|
||||||
|
@ -43,16 +43,16 @@ class BasicUIScrollViewController: UIViewController {
|
||||||
|
|
||||||
if (!didSetupConstraints) {
|
if (!didSetupConstraints) {
|
||||||
|
|
||||||
scrollView.snp_makeConstraints { make in
|
scrollView.snp.makeConstraints { make in
|
||||||
make.edges.equalTo(view).inset(UIEdgeInsetsZero)
|
make.edges.equalTo(view).inset(UIEdgeInsets.zero)
|
||||||
}
|
}
|
||||||
|
|
||||||
contentView.snp_makeConstraints { make in
|
contentView.snp.makeConstraints { make in
|
||||||
make.edges.equalTo(scrollView).inset(UIEdgeInsetsZero)
|
make.edges.equalTo(scrollView).inset(UIEdgeInsets.zero)
|
||||||
make.width.equalTo(scrollView)
|
make.width.equalTo(scrollView)
|
||||||
}
|
}
|
||||||
|
|
||||||
label.snp_makeConstraints { make in
|
label.snp.makeConstraints { make in
|
||||||
make.top.equalTo(contentView).inset(20)
|
make.top.equalTo(contentView).inset(20)
|
||||||
make.leading.equalTo(contentView).inset(20)
|
make.leading.equalTo(contentView).inset(20)
|
||||||
make.trailing.equalTo(contentView).inset(20)
|
make.trailing.equalTo(contentView).inset(20)
|
||||||
|
@ -64,4 +64,4 @@ class BasicUIScrollViewController: UIViewController {
|
||||||
|
|
||||||
super.updateViewConstraints()
|
super.updateViewConstraints()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,38 +14,38 @@ class SimpleLayoutViewController: UIViewController {
|
||||||
|
|
||||||
let blackView: UIView = {
|
let blackView: UIView = {
|
||||||
let view = UIView()
|
let view = UIView()
|
||||||
view.backgroundColor = .blackColor()
|
view.backgroundColor = .black
|
||||||
return view
|
return view
|
||||||
}()
|
}()
|
||||||
|
|
||||||
let redView: UIView = {
|
let redView: UIView = {
|
||||||
let view = UIView()
|
let view = UIView()
|
||||||
view.backgroundColor = .redColor()
|
view.backgroundColor = .red
|
||||||
return view
|
return view
|
||||||
}()
|
}()
|
||||||
|
|
||||||
let yellowView: UIView = {
|
let yellowView: UIView = {
|
||||||
let view = UIView()
|
let view = UIView()
|
||||||
view.backgroundColor = .yellowColor()
|
view.backgroundColor = .yellow
|
||||||
return view
|
return view
|
||||||
}()
|
}()
|
||||||
|
|
||||||
let blueView: UIView = {
|
let blueView: UIView = {
|
||||||
let view = UIView()
|
let view = UIView()
|
||||||
view.backgroundColor = .blueColor()
|
view.backgroundColor = .blue
|
||||||
return view
|
return view
|
||||||
}()
|
}()
|
||||||
|
|
||||||
let greenView: UIView = {
|
let greenView: UIView = {
|
||||||
let view = UIView()
|
let view = UIView()
|
||||||
view.backgroundColor = .greenColor()
|
view.backgroundColor = .green
|
||||||
return view
|
return view
|
||||||
}()
|
}()
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
view.backgroundColor = UIColor.whiteColor()
|
view.backgroundColor = UIColor.white
|
||||||
|
|
||||||
view.addSubview(blackView)
|
view.addSubview(blackView)
|
||||||
view.addSubview(redView)
|
view.addSubview(redView)
|
||||||
|
@ -60,33 +60,33 @@ class SimpleLayoutViewController: UIViewController {
|
||||||
|
|
||||||
if (!didSetupConstraints) {
|
if (!didSetupConstraints) {
|
||||||
|
|
||||||
blackView.snp_makeConstraints { make in
|
blackView.snp.makeConstraints { make in
|
||||||
make.center.equalTo(view)
|
make.center.equalTo(view)
|
||||||
make.size.equalTo(CGSizeMake(100.0, 100.0))
|
make.size.equalTo(CGSize(width: 100, height: 100))
|
||||||
}
|
}
|
||||||
|
|
||||||
redView.snp_makeConstraints { make in
|
redView.snp.makeConstraints { make in
|
||||||
make.top.equalTo(blackView.snp_bottom).offset(20.0)
|
make.top.equalTo(blackView.snp.bottom).offset(20.0)
|
||||||
make.right.equalTo(blackView.snp_left).offset(-20.0)
|
make.right.equalTo(blackView.snp.left).offset(-20.0)
|
||||||
make.size.equalTo(CGSizeMake(100.0, 100.0))
|
make.size.equalTo(CGSize(width: 100, height: 100))
|
||||||
}
|
}
|
||||||
|
|
||||||
yellowView.snp_makeConstraints { make in
|
yellowView.snp.makeConstraints { make in
|
||||||
make.top.equalTo(blackView.snp_bottom).offset(20.0)
|
make.top.equalTo(blackView.snp.bottom).offset(20.0)
|
||||||
make.left.equalTo(blackView.snp_right).offset(20.0)
|
make.left.equalTo(blackView.snp.right).offset(20.0)
|
||||||
make.size.equalTo(CGSizeMake(100.0, 100.0))
|
make.size.equalTo(CGSize(width: 100, height: 100))
|
||||||
}
|
}
|
||||||
|
|
||||||
blueView.snp_makeConstraints { make in
|
blueView.snp.makeConstraints { make in
|
||||||
make.bottom.equalTo(blackView.snp_top).offset(-20.0)
|
make.bottom.equalTo(blackView.snp.top).offset(-20.0)
|
||||||
make.left.equalTo(blackView.snp_right).offset(20.0)
|
make.left.equalTo(blackView.snp.right).offset(20.0)
|
||||||
make.size.equalTo(CGSizeMake(100.0, 100.0))
|
make.size.equalTo(CGSize(width: 100, height: 100))
|
||||||
}
|
}
|
||||||
|
|
||||||
greenView.snp_makeConstraints { make in
|
greenView.snp.makeConstraints { make in
|
||||||
make.bottom.equalTo(blackView.snp_top).offset(-20.0)
|
make.bottom.equalTo(blackView.snp.top).offset(-20.0)
|
||||||
make.right.equalTo(blackView.snp_left).offset(-20.0)
|
make.right.equalTo(blackView.snp.left).offset(-20.0)
|
||||||
make.size.equalTo(CGSizeMake(100.0, 100.0))
|
make.size.equalTo(CGSize(width: 100, height: 100))
|
||||||
}
|
}
|
||||||
|
|
||||||
didSetupConstraints = true
|
didSetupConstraints = true
|
||||||
|
@ -94,5 +94,4 @@ class SimpleLayoutViewController: UIViewController {
|
||||||
|
|
||||||
super.updateViewConstraints()
|
super.updateViewConstraints()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
Loading…
Reference in New Issue