2014-10-07 32 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