UICollectionView() constructor
The UICollectionView() constructor creates a list with a layout object.
Syntax
new UICollectionView(layout)Parameters
layout
The layout object, a UICollectionViewLayout. Currently it can only be created with UICollectionViewCompositionalLayout.layoutWithListConfiguration().
Return value
A new UICollectionView. Its frame is 0 × 0; give it a position and size with constraints or frame. It has no data source yet, and dataSource is null.
Exceptions
TypeError
layoutisn't a layout object, or wasn't given.UICollectionViewcan't be subclassed;class X extends UICollectionView {}throws onnew X(). See Native classes.
Examples
js
const list = new UICollectionView(
UICollectionViewCompositionalLayout.layoutWithListConfiguration(
new UICollectionLayoutListConfiguration('insetGrouped')));
console.log(list instanceof UIScrollView, list.dataSource);Result: prints true null.
Corresponding iOS API
[[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]. The frame parameter is removed; position it with constraints or the frame property.
See also
UICollectionLayoutListConfiguration: the list's appearance