-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectionViewController.swift
More file actions
74 lines (56 loc) · 2.42 KB
/
Copy pathCollectionViewController.swift
File metadata and controls
74 lines (56 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// CollectionViewController.swift
// StackControllerExample
//
// Created by Blaine Fahey on 3/20/16.
// Copyright © 2016 Blaine Fahey. All rights reserved.
//
import UIKit
class CollectionViewController: UICollectionViewController {
private func updateContentSize() {
preferredContentSize = collectionView!.contentSize
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
updateContentSize()
}
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
coordinator.animateAlongsideTransition(nil) { [unowned self] context in
self.updateContentSize()
}
}
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return HelloImCallie.images.count
}
override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
let header = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "Header", forIndexPath: indexPath)
return header
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CollectionViewCell
cell.label.text = "Corgi #\(indexPath.row+1)"
if let url = NSURL(string: HelloImCallie.images[indexPath.row]) {
cell.imageView.imageFromURL(url, completion: nil)
}
return cell
}
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
HelloImCallie.openInSafari()
}
}
class CollectionViewCell: UICollectionViewCell {
@IBOutlet var label: UILabel!
@IBOutlet var imageView: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
imageView.layer.cornerRadius = 15.0
}
override var highlighted: Bool {
didSet {
imageView.alpha = highlighted ? 0.7 : 1.0;
}
}
}