Update example project for Swift 3 (#376)

This commit is contained in:
Michael Buxton 2016-12-25 11:21:10 +00:00 committed by Robert Payne
parent 3ce0d32bce
commit 32cd509939
4 changed files with 59 additions and 62 deletions

View File

@ -13,19 +13,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
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 navigationController:UINavigationController = UINavigationController(rootViewController: listViewController);
self.window!.rootViewController = navigationController;
self.window!.backgroundColor = UIColor.whiteColor()
self.window!.backgroundColor = UIColor.white
self.window!.makeKeyAndVisible()
return true
}
}

View File

@ -19,29 +19,28 @@ class ListViewController: UITableViewController {
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 {
let cell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier)! as UITableViewCell
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
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]
return cell
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return demos.count
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 0 {
let viewController = SimpleLayoutViewController()
navigationController?.pushViewController(viewController, animated: true)
} else if indexPath.row == 1 {
let viewController = BasicUIScrollViewController()
let viewController = ViewController()
navigationController?.pushViewController(viewController, animated: true)
}
}
}

View File

@ -17,10 +17,10 @@ class BasicUIScrollViewController: UIViewController {
let label: UILabel = {
let label = UILabel()
label.backgroundColor = .blueColor()
label.backgroundColor = .blue
label.numberOfLines = 0
label.lineBreakMode = .ByClipping
label.textColor = .whiteColor()
label.lineBreakMode = .byClipping
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: "")
return label
}()
@ -28,11 +28,11 @@ class BasicUIScrollViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.whiteColor()
view.backgroundColor = UIColor.white
view.addSubview(scrollView)
contentView.backgroundColor = UIColor.lightGrayColor()
contentView.backgroundColor = UIColor.lightGray
scrollView.addSubview(contentView)
contentView.addSubview(label)
@ -43,16 +43,16 @@ class BasicUIScrollViewController: UIViewController {
if (!didSetupConstraints) {
scrollView.snp_makeConstraints { make in
make.edges.equalTo(view).inset(UIEdgeInsetsZero)
scrollView.snp.makeConstraints { make in
make.edges.equalTo(view).inset(UIEdgeInsets.zero)
}
contentView.snp_makeConstraints { make in
make.edges.equalTo(scrollView).inset(UIEdgeInsetsZero)
contentView.snp.makeConstraints { make in
make.edges.equalTo(scrollView).inset(UIEdgeInsets.zero)
make.width.equalTo(scrollView)
}
label.snp_makeConstraints { make in
label.snp.makeConstraints { make in
make.top.equalTo(contentView).inset(20)
make.leading.equalTo(contentView).inset(20)
make.trailing.equalTo(contentView).inset(20)

View File

@ -14,38 +14,38 @@ class SimpleLayoutViewController: UIViewController {
let blackView: UIView = {
let view = UIView()
view.backgroundColor = .blackColor()
view.backgroundColor = .black
return view
}()
let redView: UIView = {
let view = UIView()
view.backgroundColor = .redColor()
view.backgroundColor = .red
return view
}()
let yellowView: UIView = {
let view = UIView()
view.backgroundColor = .yellowColor()
view.backgroundColor = .yellow
return view
}()
let blueView: UIView = {
let view = UIView()
view.backgroundColor = .blueColor()
view.backgroundColor = .blue
return view
}()
let greenView: UIView = {
let view = UIView()
view.backgroundColor = .greenColor()
view.backgroundColor = .green
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.whiteColor()
view.backgroundColor = UIColor.white
view.addSubview(blackView)
view.addSubview(redView)
@ -60,33 +60,33 @@ class SimpleLayoutViewController: UIViewController {
if (!didSetupConstraints) {
blackView.snp_makeConstraints { make in
blackView.snp.makeConstraints { make in
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
make.top.equalTo(blackView.snp_bottom).offset(20.0)
make.right.equalTo(blackView.snp_left).offset(-20.0)
make.size.equalTo(CGSizeMake(100.0, 100.0))
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))
}
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(CGSizeMake(100.0, 100.0))
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))
}
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(CGSizeMake(100.0, 100.0))
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))
}
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(CGSizeMake(100.0, 100.0))
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))
}
didSetupConstraints = true
@ -94,5 +94,4 @@ class SimpleLayoutViewController: UIViewController {
super.updateViewConstraints()
}
}