FittingGridFlowLayout
public class FittingGridFlowLayout: UICollectionViewFlowLayout
UICollectionViewFlowLayout
subclass that shows items as grid that fit horizontally to a fixed margin rather than a fixed size. The size is determined by the itemTargetWidth
, singleColumnRatio
and multiColumnRatio
. The target width may not be realized, but is used to determined the number of columns in the layout.
-
The actual number of items filling the width of the collection view given the itemTargetWidth, line spacing, item spacing and width of the collection view.
Declaration
Swift
private(set) public var columnCount:Int = 0
-
The target width of all items in the grid. Default is 380. If the actual number of items that will fit given the item and line spacing is fractional, the number of items wide is the rounded value. The actual size of the items with therefore vary from this value in most cases. The height is determined by the singleColumnRatio and multiColumnRatio properties. Default is 380.0.
Declaration
Swift
public var itemTargetWidth:CGFloat = 380.0
-
The ratio of the items if there is only a single column. Default is 0.5625.
Declaration
Swift
public var singleColumnRatio:CGFloat = 0.5625
-
The ratio of the items if there are multiple columns. Default is 0.75.
Declaration
Swift
public var multiColumnRatio:CGFloat = 0.75
-
Returns the number of items in a row based on the ratio properties given the contentWidth. In prepareLayout this method is called with the collectionView’s bounds’s width.
Declaration
Swift
public func columnCountForWidth(contentWidth:CGFloat) -> Int
-
Returns the item size of items based on the ratio properties given the contentWidth. In prepareLayout this method is called with the collectionView’s bounds’s width.
Declaration
Swift
public func itemSizeForWidth(contentWidth:CGFloat) -> CGSize
-
Calculates the column count for the size of the current
collectionView
, setting theitemSize
based onitemSizeForWidth(_:)
.Declaration
Swift
override public func prepareLayout()
-
Invalidates the layout based on whether or not the width of
newBounds
differs from that of the currentcollectionView
.Declaration
Swift
override public func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool