FUIHorizontalScrollCollectionViewLayout
@MainActor
open class FUIHorizontalScrollCollectionViewLayout : UICollectionViewLayout
This layout should be used when the user should pan horizontally in the collection view, to view items off-screen to the left or right. Items in a section extend in a single row to infinity, so items will not wrap to new lines.
A developer should set the itemSize property of the layout, to specify the standard dimensions of the cell items.
Code usage
Assign an instance of FUIHorizontalScrollCollectionViewLayout to your collection view.
self.collectionView.collectionViewLayout = FUICollectionViewLayout.horizontalScrollImplement collectionView(_:cellForItemAt:) dataSource.
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FUIObjectCollectionViewCell.reuseIdentifier, for: indexPath) as! FUIObjectCollectionViewCell //You may use any type of collection view cell here. //configue cell here //... return cell }Implement following methods if you need section header/footer. You can also set headerReferenceHeight/footerReferenceHeight to apply same height for all headers/footers.
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { let view = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "Header", for: indexPath) as! FUICollectionSectionHeaderFooterView //configue header/footer view here //... return view }
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { switch section { case 0: return CGSize(width: 40, height: 40) default: return CGSize(width: 60, height: 60) }
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize { switch section { case 0: return CGSize(width: 40, height: 40) default: return CGSize(width: 60, height: 60) }
-
A boolean value controls whether the height of the cell on the same row is adjusted to match the maximum cell height. The default is
false.Declaration
Swift
@MainActor public var shouldApplyIdenticalCellHeight: Bool { get set } -
The first cell stops at a specific position after scrolling if it is
true; otherwise it can stop at any position when it isfalse.Declaration
Swift
@MainActor public var isSnapping: Bool -
Number of columns of the layout. The default is
nil.Declaration
Swift
@MainActor public var numberOfColumns: Int? { get set } -
The default size(50*50) to use for cells.
Declaration
Swift
@MainActor open var itemSize: CGSize { get set } -
The estimated size of cells in the collection view.
Providing an estimated cell size can improve the performance of the collection view when the cells adjust their size dynamically. Specifying an estimate value lets the collection view defer some of the calculations needed to determine the actual size of its content. Specifically, cells that are not onscreen are assumed to be the estimated height.
The default value of this property is
CGSizeZero. Setting it to any other value causes the collection view to query each cell for its actual size using the cell’spreferredLayoutAttributesFitting(_:)method. If all of your cells are the same height, use theitemSize property, instead of this property, to specify the cell size instead.Declaration
Swift
@MainActor open var estimatedItemSize: CGSize { get set } -
The margins used to lay out content in a section.
Declaration
Swift
@MainActor open var sectionInset: UIEdgeInsets { get set } -
The default size to use for section headers. Implementing collectionView(_:layout:referenceSizeForHeaderInSection:) will override this property.
Declaration
Swift
@MainActor open var headerReferenceSize: CGSize { get set } -
The default size to use for section footers. Implementing collectionView(_:layout:referenceSizeForFooterInSection:) will override this property.
Declaration
Swift
@MainActor open var footerReferenceSize: CGSize { get set } -
The minimum spacing to use between items in the same row.
Declaration
Swift
@MainActor open var minimumInteritemSpacing: CGFloat { get set } -
The vertical alignment of cells in the collection view.
Declaration
Swift
@MainActor open var alignment: FUICollectionViewVerticalAlignment { get set } -
Undocumented
Declaration
Swift
@MainActor open override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint -
Undocumented
Declaration
Swift
@MainActor open override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint