我有一个UICollectionView显示照片的。我已经使用UICollectionViewFlowLayout. 它工作得很好,但我想在边距上有间距。是否可以使用UICollectionViewFlowLayout或必须自己实现UICollectionViewLayout?
UICollectionView
UICollectionViewFlowLayout
UICollectionViewLayout
您可以使用您的collectionView:layout:insetForSectionAtIndex:方法UICollectionView或设置附加到您sectionInset的对象的属性:UICollectionViewFlowLayout``UICollectionView
collectionView:layout:insetForSectionAtIndex:
sectionInset
UICollectionViewFlowLayout``UICollectionView
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{ return UIEdgeInsetsMake(top, left, bottom, right); }
或者
UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init]; [aFlowLayout setSectionInset:UIEdgeInsetsMake(top, left, bottom, right)];
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { return UIEdgeInsets(top: 25, left: 15, bottom: 0, right: 5) }