1.add collection view to view controller.
2.add 4 constraints. (0,0,0,0)
3.add new file.(cocoa class NSCollectionView)
4.set new file 200*50.
5.add label.
6.add object and set its class to 'MyCollectionViewItem'
7.connect object to the MyCollectionViewItem's view.(view)
8.connect collection view's datasource to view controller.
9.view controller add protocol ‘NSCollectionViewDataSource’
10.provide two method.
- (NSInteger)collectionView:(nonnull NSCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 2;}- (nonnull NSCollectionViewItem *)collectionView:(nonnull NSCollectionView *)collectionView itemForRepresentedObjectAtIndexPath:(nonnull NSIndexPath *)indexPath { NSCollectionViewItem *item = [collectionView makeItemWithIdentifier:@"MyCollectionViewItem" forIndexPath:indexPath]; return item;}
11.set collection view's item size 200*50.