ios UICollectionView分离单元格之间的顶部/底部
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18029743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ios UICollectionView separation on top / bottom between cells
提问by manuelBetancurt
I have a collection view, is working fine, and I have adjusted the separation for the X padding,
我有一个集合视图,工作正常,我已经调整了 X 填充的分隔,
and it works fine, but for the Y padding between cells, doesn't seem to adjust to NO separation
它工作正常,但对于单元格之间的 Y 填充,似乎没有调整到无分离
This is my code for the layout
这是我的布局代码
UICollectionViewFlowLayout *layoutItem=[[UICollectionViewFlowLayout alloc] init];
layoutItem.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
So how can I set the separation on top / bottom to 0px? Between cells?,
那么如何将顶部/底部的分隔设置为 0px?细胞之间?,
thanks!
谢谢!
回答by Warewolf
you will see only top y padding at first time. And For showing bottom y padding you need more data that CollectionView frame height. When you scroll up collection view you will see bottom y padding.
您第一次只会看到顶部 y 填充。并且为了显示底部 y 填充,您需要更多的 CollectionView 框架高度数据。当您向上滚动集合视图时,您将看到底部 y 填充。
I used collectionView like this
我像这样使用 collectionView
https://stackoverflow.com/a/17856406/1305001
https://stackoverflow.com/a/17856406/1305001
When I set
当我设置
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(60, 10, 50, 10);
}
The output will come as First time..
输出将作为第一次..
When you scrolled up collectionView you will see bottom padding..
当您向上滚动 collectionView 时,您将看到底部填充..
Use this for verticle line spacing between cells
将此用于单元格之间的垂直线间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return 5;
}
Will look like
看起来像
回答by simon_smiley
You can also do it a much simpler way using the collection view flow layout.
您还可以使用集合视图流布局以更简单的方式来完成。
Set up the flow layout (remember to add the delegate in your header):
设置流程布局(记得在标题中添加委托):
UICollectionViewFlowLayout * stickerFlowLayout = [[UICollectionViewFlowLayout alloc] init];
stickerFlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
**stickerFlowLayout.minimumLineSpacing = 10;**
stickerFlowLayout.minimumInteritemSpacing = 5;
stickerFlowLayout.sectionInset = UIEdgeInsetsMake(10, 25, 20, 25);
// Set up the collection view
collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:stickerFlowLayout];
collectionView.delegate = self;
collectionView.dataSource = self;
etc
As you can see we can easily set the line spacing using:
如您所见,我们可以使用以下方法轻松设置行距:
**stickerFlowLayout.minimumLineSpacing = 10;**
We can also alter the other attributes
我们还可以改变其他属性
stickerFlowLayout.minimumInteritemSpacing = 5;
With the interitem spacing affecting the spaces between items (similar but different to the line spacing)
用interitem间距影响item之间的空间(与行间距相似但不同)
Using the flow layout you can save on a huge amount of code and set your collection view up programatically all in one place (just setting the inset and line spacing has immediately saved me two extra unneeded functions)
使用流布局,您可以节省大量代码,并在一个地方以编程方式设置集合视图(只需设置插图和行间距即可立即为我节省两个额外不需要的功能)