2014-10-07 62 views
0

我想创建一个简单的collectionView像pinterest。我遇到了一个问题,我已经设置了图像中的边距,但是因为您可以看到中间边距为20,因为左右两边都是10,我怎么能让它也是10.我试过改变一些值,但它不起作用。CollectionView保证金不一样

enter image description here

拟合所有方向

有没有更好的办法?

func collectionView(collectionView : UICollectionView,layout collectionViewLayout:UICollectionViewLayout,sizeForItemAtIndexPath indexPath:NSIndexPath) -> CGSize 
{ 

    return CGSizeMake(self.collectionView!.frame.width/2-20, self.collectionView!.frame.width/2-20+50) 
} 

回答

0

使用自动布局和查看约束。这将允许您让每个瓷砖保持其不同方向的间距和比例。

see the apple docs

+0

但我不能在UICollectionViewCells上使用禁忌。有没有更好的方式使它适合所有的方向,而不是我在sizeForItemAtIndexPath中所做的? – 2014-10-07 18:23:38