Jua*_*njo 6 objective-c ios uicollectionview
我想有一个UICollectionView,在第一行有一个单元格的所有行的宽度,第二行有3个单元格.我研究了文档,但我无法做到.像这样的东西:

提前致谢
art*_*dev 12
在故事板中的集合视图中创建2 Cell原型,并设置它们重用标识符

在ViewController的.m文件中实现此功能
- (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*/)// e.g. 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*/) // e.g. indexPath.row % 3 != 0
return CGSizeMake(65, 50);
return CGSizeMake(318, 50);
}
Run Code Online (Sandbox Code Playgroud)
完成后你会有这样的事情:

| 归档时间: |
|
| 查看次数: |
1866 次 |
| 最近记录: |