我试图让细胞尽可能多地占据宽度,但我最终还是这样:
我试图在xcode中删除边距,行间距等:
但水平边距仍然很大,我希望应用相同的垂直边距。
有什么想法吗?
P.S附加示例代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.collectionView.delegate = self;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 9;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
CollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];
return cell;
}
答案 0 :(得分:0)
您将“收集”单元格设置为100x100,并将其设置为3行。
所以UICollectionView最小为300/300。如果您将视图设置为320(正常的iPhone宽度),则“集合视图”会自动在单元格之间设置填充。
编辑:
尝试:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
CollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];
//3 because you wanted 3 cells. 18 is the min padding between the cell.
cell.frame.size.width = collectionView.frame.size.width/3-18;
return cell;
}