在UICollectionView中显示不同数量的单元格
我想有一个UICollectionView
,在第一行有一个单元格的所有行的宽度,第二行有3个单元格。 我已经研究过文档,但是我无法做到。 像这样的东西:
提前致谢
在故事板中的集合视图中创build2个单元格原型,并将它们设置为重用标识符
在你的ViewController的.m文件中实现这个function
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 6; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell; if (/*condition for small cell*/)// eg indexPath.row % 3 != 0 cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"smallCell" forIndexPath:indexPath]; else cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"bigCell" forIndexPath:indexPath]; return cell; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { if (/*condition for small cell*/) // eg indexPath.row % 3 != 0 return CGSizeMake(65, 50); return CGSizeMake(318, 50); }
做完这个之后你会得到这样的东西:
- 如何在iOS objective-C中为vr应用程序并排显示相机的两个预览?
- iOS 7 – UISegmentedControl没有保持突出显示?
- 我可以知道在viewWillAppear它被称为导航控制器popup后(后退button)?
- 缺省实现中缺lessUITableViewCell detailTextLabel
- UITableView重复Firebase数据
- 如何输出CIFilter到相机视图?
- AVAudioSession AVAudioSessionCategoryPlayAndRecord毛刺
- AVSpeechSynthesizer错误AudioSession
- 将UIButton的背景颜色从WhiteColoranimation到RedColor