Skip to content

Commit

Permalink
Merge pull request #9 from Jack-Rouleau/grid-cell-resize
Browse files Browse the repository at this point in the history
Grid cell resize
  • Loading branch information
younatics authored Oct 11, 2017
2 parents f9afc89 + 923f8d5 commit 046c4e4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ xcuserdata/
*.moved-aside
*.xccheckout
*.xcscmblueprint
.DS_Store

## Obj-C/Swift specific
*.hmap
Expand Down
8 changes: 8 additions & 0 deletions MediaBrowser/MediaBrowserDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ public protocol MediaBrowserDelegate: class {
- Parameter index: Int
*/
func title(for mediaBrowser: MediaBrowser, at index: Int) -> String?

/**
Optional protocol for grid cells resizing
- Returns: Optional CGSize
*/
func gridCellSize() -> CGSize?
}

public extension MediaBrowserDelegate {
Expand All @@ -115,4 +121,6 @@ public extension MediaBrowserDelegate {
func mediaDid(selected: Bool, at index: Int, in mediaBrowser: MediaBrowser) { }

func title(for mediaBrowser: MediaBrowser, at index: Int) -> String? { return nil }

func gridCellSize() -> CGSize? { return nil }
}
4 changes: 4 additions & 0 deletions MediaBrowser/MediaGridViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ class MediaGridViewController: UICollectionViewController, UICollectionViewDeleg
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if let delegateSize = self.browser?.delegate?.gridCellSize() {
return delegateSize
}

let value = CGFloat(floorf(Float((view.bounds.size.width - (columns - 1.0) * gutter - 2.0 * margin) / columns)))

return CGSize(width: value, height: value)
Expand Down
9 changes: 9 additions & 0 deletions MediaBrowserDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ extension ViewController {

self.tableView.deselectRow(at: indexPath, animated: true)
}

// Uncomment this to resize the grid cells when viewing with grid
/*
func gridCellSize() -> CGSize? {
let desiredSize = self.view.frame.size.width * 0.3

return CGSize(width: desiredSize, height: desiredSize)
}
*/

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellCheck = tableView.dequeueReusableCell(withIdentifier: "Cell")
Expand Down

0 comments on commit 046c4e4

Please sign in to comment.