[![在此处输入图像描述] [1]] [1] [![在此处输入图像描述] [2]] [2]我正在水平使用collectionView
单元格来获取JSON数据,但是问题是我正在使用高度为100的像元大小,宽度为启用分页的屏幕的view
,但是问题是我可以滚动它,但我想使边缘的前导和尾部间距为20。我移动的单元格无法像第一个单元格一样获得前后的单元格边缘
class MainContainer: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet weak var collectionview: UICollectionView!
@IBOutlet weak var FlowLayout: UICollectionViewFlowLayout!
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: (self.view.frame.width - 20), height: 100)
}
答案 0 :(得分:0)
您需要在collectionView中删除单元格和行的最小间距
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
答案 1 :(得分:0)
在布局中以编程方式更改,尝试在控制器中尝试viewDidLoad(),因此它会覆盖滚动方向的默认值
FlowLayout.scrolldirection = .horizontal
答案 2 :(得分:0)
尝试以下代码:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: (collectionView.frame.width - 20), height: 100)
}
答案 3 :(得分:0)
**步骤-1:**在StoryBoard中创建CollectionView(高度,宽度,最小间距,左右)
**步骤-2:**导入(UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout)
**步骤-3:**
if(Activity1.DOING_PASS){
// do normal
}
else{
Intent i = new Intent(this, Activity1.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP || Intent.FLAG_ACTIVITY_CLEAR_TASK || Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
**步骤-4:**实现方法
@IBOutlet var collViewFeaturedEvents: UICollectionView!
@IBOutlet var collViewEventsHeight: NSLayoutConstraint!
self.collViewFeaturedEventsHeight.constant = self.collViewFeaturedEvents.collectionViewLayout.collectionViewContentSize.height self.view.updateConstraintsIfNeeded()