---追記---
参照先がSwiftだったのでCocoaでのサンプルコードも載せておきます。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CGRect bounds = [[UIScreen mainScreen] bounds];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(50, 100);
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
layout.minimumLineSpacing = 0.0;
layout.minimumInteritemSpacing = 0.0;
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:bounds collectionViewLayout:layout];
[collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class])];
collectionView.frame = CGRectMake(0, 0, bounds.size.width, 100);
[self.view addSubview:collectionView];
//クラスに<UICollectionViewDataSource>を設定しておいてください
collectionView.dataSource = self;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 20;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = indexPath.row;
UICollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class]) forIndexPath:indexPath];
if(cell == nil)
{
}
cell.backgroundColor = [UIColor colorWithRed:row * 20 / 255.0 green:1.0 blue:0.0 alpha:1.0];
return cell;
}