Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions PinterestLayout/PinterestLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public class PinterestLayout: UICollectionViewLayout {
/**
Cell padding.
*/
public var cellPadding: CGFloat = 0
public var cellPaddingTop: CGFloat = 0
public var cellPaddingSide: CGFloat = 0


private var cache = [PinterestLayoutAttributes]()
Expand Down Expand Up @@ -76,7 +77,7 @@ public class PinterestLayout: UICollectionViewLayout {
override public func prepare() {
if cache.isEmpty {
let collumnWidth = contentWidth / CGFloat(numberOfColumns)
let cellWidth = collumnWidth - (cellPadding * 2)
let cellWidth = collumnWidth - (cellPaddingSide * 2)

var xOffsets = [CGFloat]()

Expand Down Expand Up @@ -129,7 +130,7 @@ public class PinterestLayout: UICollectionViewLayout {
heightForAnnotationAtIndexPath: indexPath,
withWidth: cellWidth
)
let cellHeight = cellPadding + imageHeight + annotationHeight + cellPadding
let cellHeight = cellPaddingTop + imageHeight + annotationHeight + cellPaddingTop

let frame = CGRect(
x: xOffsets[column],
Expand All @@ -138,7 +139,7 @@ public class PinterestLayout: UICollectionViewLayout {
height: cellHeight
)

let insetFrame = frame.insetBy(dx: cellPadding, dy: cellPadding)
let insetFrame = frame.insetBy(dx: cellPaddingSide, dy: cellPaddingTop)
let attributes = PinterestLayoutAttributes(
forCellWith: indexPath
)
Expand Down
3 changes: 2 additions & 1 deletion PinterestLayout/PinterestVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ open class PinterestVC: UICollectionViewController, PinterestLayoutDelegate {
return layout
}()
layout.delegate = self
layout.cellPadding = 5
layout.cellPaddingTop = 5
layout.cellPaddingSide = 5
layout.numberOfColumns = 2
}

Expand Down
3 changes: 2 additions & 1 deletion PinterestLayoutExample/CustomCollectionVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class CustomCollectionVC: UICollectionViewController {
return layout
}()
layout.delegate = self
layout.cellPadding = 5
layout.cellPaddingTop = 5
layout.cellPaddingSide = 5
layout.numberOfColumns = 2
}
}
Expand Down