以一种两者之间没有临时间距的方式设置UICollectionViewCell的大小 [英] Setting size of UICollectionViewCell in a way that there is no interim spacing in between

查看:306
本文介绍了以一种两者之间没有临时间距的方式设置UICollectionViewCell的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 UICollectionView ,我想要并排放置七个单元格。应该使用整个屏幕。目前,我正在使用集合视图的宽度并将其除以7。现在我在iPhone 4上得到 45.71429 的项目宽度。在一些单元格之间有一个临时间距。我怎么处理这个?我想填写整个屏幕,所有项目都应该有相同的大小。

I'm using an UICollectionView on which I want to place seven cells side by side. The whole screen should be used for this. Currently, I'm using the width of the collection view and divide it by seven. Now I get an item width of 45.71429 on an iPhone 4. Between some cells there is an interim spacing. How can I handle this? I want to fill out the whole screen and all items should have the same size.

我想到的一个选项是舍入值并使用剩余的值作为插图。但是不是有更好的方法吗?

One option which comes to my mind is to round the value and use the remaining value as inset. But isn't there a better way?

推荐答案

步骤1:实施UICollectionViewDelegateFlowLayout(如果没有完成) )。

Step 1: Implement UICollectionViewDelegateFlowLayout(if not done).

步骤2:使用UICollectionViewDelegateFlowLayout的委托方法。

Step 2: Use delegate method of UICollectionViewDelegateFlowLayout.

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
{
return CGSizeMake((UIScreen.mainScreen().bounds.width)/7,120); //use height whatever you wants.
}

第3步:转到 XIB或者StoryBoard ,你有CollectionView。

Step 3: Go to XIB or StoryBoard where you have your CollectionView.

第4步: XIB或StoryBoard 中你在哪里有你的CollectionView,点击CollectionView。

Step 4: In XIB or StoryBoard where you have your CollectionView, click on CollectionView.

第5步:转到InterfaceBuilder,然后在第二个标签(即:Size Inspector)中设置最小间距

Step 5: Go to InterfaceBuilder, then in second last tab (ie: Size Inspector) set Min Spacing

对于Cells = 0

For Cells = 0

对于Lines = 0

For Lines = 0

它。

这篇关于以一种两者之间没有临时间距的方式设置UICollectionViewCell的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆