Skip to content

Instantly share code, notes, and snippets.

@aclissold
Created December 7, 2014 02:29
Show Gist options
  • Save aclissold/75a50d4a05907b73dcf5 to your computer and use it in GitHub Desktop.
Save aclissold/75a50d4a05907b73dcf5 to your computer and use it in GitHub Desktop.
For github.com/Keithbsmiley/swift.vim/pull/30
// MARK: NHBalancedFlowLayoutDelegate
func collectionView(collectionView: UICollectionView!,
layout collectionViewLayout: NHBalancedFlowLayout!,
preferredSizeForItemAtIndexPath indexPath: NSIndexPath!) -> CGSize {
if UIScreen.mainScreen().scale == 1.0 {
var size = photos[indexPath.item].size
size.width /= 2
size.height /= 2
return size
}
return photos[indexPath.item].size
}
// MARK: UICollectionViewDataSource
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView,
numberOfItemsInSection section: Int) -> Int {
return photos.count
}
override func collectionView(collectionView: UICollectionView,
cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(photoCellID,
forIndexPath: indexPath) as PhotoCell
if let highResPhoto = highResPhotos[indexPath.item] {
cell.imageButton.setBackgroundImage(highResPhoto, forState: .Normal)
} else {
cell.imageButton.setBackgroundImage(photos[indexPath.item], forState: .Normal)
}
cell.imageButton.tag = indexPath.item
return cell
}
// MARK: NHBalancedFlowLayoutDelegate
func collectionView(collectionView: UICollectionView!,
layout collectionViewLayout: NHBalancedFlowLayout!,
preferredSizeForItemAtIndexPath indexPath: NSIndexPath!) -> CGSize {
if UIScreen.mainScreen().scale == 1.0 {
var size = photos[indexPath.item].size
size.width /= 2
size.height /= 2
return size
}
return photos[indexPath.item].size
}
// MARK: UICollectionViewDataSource
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView,
numberOfItemsInSection section: Int) -> Int {
return photos.count
}
override func collectionView(collectionView: UICollectionView,
cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(photoCellID,
forIndexPath: indexPath) as PhotoCell
if let highResPhoto = highResPhotos[indexPath.item] {
cell.imageButton.setBackgroundImage(highResPhoto, forState: .Normal)
} else {
cell.imageButton.setBackgroundImage(photos[indexPath.item], forState: .Normal)
}
cell.imageButton.tag = indexPath.item
return cell
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment