my problem is that the uicollectionview cell is moving to left when the next cell jumps to the second line and there is space in the first line (space which didnt fit to contain the next cell), how could i prevent the cell from moving to the right, even when there is still space, i need some thing like setMaximumSpace between cells (which doesnt exist) ?
here is my code :
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
}