SnapKit/Example-iOS/demos/BasicUIScrollViewController...

68 lines
4.0 KiB
Swift
Raw Normal View History

2016-03-01 18:14:50 +08:00
//
// BasicUIScrollViewController.swift
// SnapKit
//
// Created by Spiros Gerokostas on 01/03/16.
// Copyright © 2016 SnapKit Team. All rights reserved.
//
import UIKit
class BasicUIScrollViewController: UIViewController {
2016-03-01 19:00:56 +08:00
var didSetupConstraints = false
let scrollView = UIScrollView()
let contentView = UIView()
let label: UILabel = {
let label = UILabel()
label.backgroundColor = .blueColor()
label.numberOfLines = 0
label.lineBreakMode = .ByClipping
label.textColor = .whiteColor()
2016-03-01 19:23:33 +08:00
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: "")
2016-03-01 19:00:56 +08:00
return label
}()
2016-03-01 18:14:50 +08:00
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.whiteColor()
2016-03-01 19:00:56 +08:00
view.addSubview(scrollView)
2016-03-01 19:13:24 +08:00
contentView.backgroundColor = UIColor.lightGrayColor()
2016-03-01 19:00:56 +08:00
scrollView.addSubview(contentView)
contentView.addSubview(label)
view.setNeedsUpdateConstraints()
}
override func updateViewConstraints() {
if (!didSetupConstraints) {
2016-03-01 19:13:24 +08:00
2016-05-12 16:52:16 +08:00
scrollView.snp_makeConstraints { make in
2016-03-01 19:00:56 +08:00
make.edges.equalTo(view).inset(UIEdgeInsetsZero)
}
2016-05-12 16:52:16 +08:00
contentView.snp_makeConstraints { make in
2016-03-01 19:00:56 +08:00
make.edges.equalTo(scrollView).inset(UIEdgeInsetsZero)
make.width.equalTo(scrollView)
}
2016-05-12 16:52:16 +08:00
label.snp_makeConstraints { make in
2016-03-01 19:00:56 +08:00
make.top.equalTo(contentView).inset(20)
make.leading.equalTo(contentView).inset(20)
make.trailing.equalTo(contentView).inset(20)
make.bottom.equalTo(contentView).inset(20)
}
didSetupConstraints = true
}
super.updateViewConstraints()
2016-03-01 18:14:50 +08:00
}
}