UICollectionView 在每个滚动页面上有两行
UICollectionView two rows on each scroll page
我正在尝试使用 Collection View 实现这样的效果:
这些单元格的宽度应自动调整为屏幕宽度。每个单元格的高度应为 45%(10% 用于此黑色间隙)。我尝试了很多组合,但我无法以任何方式实现这一目标。在此先感谢您的帮助。
最好的祝福,
阿德里安.
将 collectionView 宽度设置为全屏。实现这些委托方法
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(collectionView.bounds.size.width, height);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(0, 0, bottom, 0);
}
我在这里附上了一张图片
我采用了适合屏幕宽度和屏幕尺寸一半的 CollectionView Cell,采用 UIView 并将其放入集合视图单元格中,从底部开始填充 10-15 像素,清除集合视图背景的颜色,这应该会给你 CollectionViewCell 单元格彼此填充的错觉。
无论您想在 CollectionView 中显示什么元素,请将其添加到 CollectionViewCell 单元格内视图内的视图中
我正在尝试使用 Collection View 实现这样的效果:
这些单元格的宽度应自动调整为屏幕宽度。每个单元格的高度应为 45%(10% 用于此黑色间隙)。我尝试了很多组合,但我无法以任何方式实现这一目标。在此先感谢您的帮助。 最好的祝福, 阿德里安.
将 collectionView 宽度设置为全屏。实现这些委托方法
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(collectionView.bounds.size.width, height);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(0, 0, bottom, 0);
}
我在这里附上了一张图片
我采用了适合屏幕宽度和屏幕尺寸一半的 CollectionView Cell,采用 UIView 并将其放入集合视图单元格中,从底部开始填充 10-15 像素,清除集合视图背景的颜色,这应该会给你 CollectionViewCell 单元格彼此填充的错觉。 无论您想在 CollectionView 中显示什么元素,请将其添加到 CollectionViewCell 单元格内视图内的视图中