本人ios初學(xué)者,為自己學(xué)習(xí)方便,復(fù)制各位大神的學(xué)習(xí)性文章放在自己簡書里,僅作為自己學(xué)習(xí)方便使用,如果作者疑此行為侵權(quán),請隨時(shí)聯(lián)系本人刪除,如有共同學(xué)習(xí)者復(fù)制此文章,請注明原出處
原文地址:http://www.cnblogs.com/davidgu/p/4975042.html
?讓每個(gè)元素大小變?yōu)?04 x 104Step?
1:在你的視圖控制器頭文件中實(shí)現(xiàn)遵守協(xié)議
@interface CollectionViewController ()<UICollectionViewDelegateFlowLayout>
@end
Step 2:
設(shè)置每個(gè)單元格的大小
eg:
復(fù)制代碼
- (CGSize) collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(104.0f, 104.0f);
}
復(fù)制代碼
Step 3:
設(shè)置單元格間的橫向間距
eg:
- (CGFloat) collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return 2.0f;
}
Step 4:
設(shè)置縱向的行間距
eg:
- (CGFloat) collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return 2.0f;
}
step 5:
通過調(diào)整inset使單元格頂部和底部都有間距(inset次序: 上,左,下,右邊)
eg:
- (UIEdgeInsets) collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(2.0f, 0.0f, 2.0f, 0.0f);
}