[英]Populate UICollectionView from left to right when scrolling direction is horizontal
When scrolling direction is horizontal cells are added in UICollectionView
from top to bottom 当滚动方向为水平时,在
UICollectionView
中从上到下添加单元格
For scrolling direction = vertical, they are added from left to right. 对于滚动方向=垂直,它们是从左到右添加的。
The question is, if there is any way to add cells from left to right when scrolling direction is horizontal ? 问题是,当滚动方向是水平时,是否有任何方法可以从左到右添加单元格?
The order is automatically generated by the scroll direction, which is set by default. 订单由滚动方向自动生成,默认设置。
What you can do is to add a custom layout for the UICollectionView by using the layoutAttributesForItemAtIndexPath method to set a frame for each individual cell. 您可以做的是通过使用layoutAttributesForItemAtIndexPath方法为每个单独的单元格设置框架,为UICollectionView添加自定义布局。
-(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewLayoutAttributes* attr = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
CGRect cellFrame = CGRectMake(/* calculate your origin x */,
/* calculate your origin y */,
/* calculate your width */,
/* calculate your height */);
attr.frame = cellFrame;
return attr;
}
You need to use UICollectionViewFlowLayout
and set the scrollDirection
property to 您需要使用
UICollectionViewFlowLayout
并将scrollDirection
属性设置为
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
Default setting is is vertical (top to bottom) 默认设置为垂直(从上到下)
每个集合视图都有布局属性,允许您更改滚动方向。您可以这样做:
collectionView.collectionViewLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.