0
我的问题是,当下一个单元格跳到第二行并且第一行中存在空格时,uicollectionview单元格正在向左移动(空格不适合包含下一个单元格),如何防止单元格移动到右侧,即使仍有空间时,我还需要像单元格之间的setMaximumSpace(它不存在)之类的东西?防止uicollectionview单元格窗体在有空间时向右移动SWIFT
这里是我的代码:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = mycollectionView.dequeueReusableCellWithReuseIdentifier("CharakterCell", forIndexPath: indexPath) as CharakterCollectionViewCell
for (var i=0 ; i<4 ; i++)
{
if (collectionCellIndex[i] == nil)
{
collectionCellIndex[i] = indexPath
println("\(collectionCellIndex[i])")
println(i)
break
}
}
return cell
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout:UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
var size = CGSize(width: 0, height: 0)
var label = UILabel()
if (selectedCharInCollectionNames[indexPath.row] == "")
{
size = CGSize(width: 40, height: 30)
}
else
{
label.text = selectedCharInCollectionNames[indexPath.row]
label.sizeToFit()
var width = label.frame.width
size = CGSize(width: (width+25), height: 30)
}
label.sizeToFit()
return size
}
private let sectionInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
func collectionView(collectionView: UICollectionView!,
layout collectionViewLayout: UICollectionViewLayout!,
insetForSectionAtIndex section: Int) -> UIEdgeInsets {
return sectionInsets
}