Search code examples
iosswiftuicollectionviewuikituicollectionviewcell

UIKit - UICollectionView - presents only half of the last cell


I have a horizontal UICollectionView with custom UICollectionViewCell with UILabel

-which I've built with the interface builder storyboard + xib file for the cell)

I want to have some space between the cells - so I've set "Min Spacing" to 10 (for lines)

also Estimate Size is set to : 120 width, 25 Height

The problem is: when I scroll to the end, the last cell is being cut, and only half of it is being presented, as shown in the picture:

enter image description here

EDIT (Constraints):

Constraints on the UICollectionView are (with the interface builder): Align Top to: Safe Area (8 to the top) Align Trailing to: Safe Area (0 to the right) Align Leading to : Safe Area (0 to the left) Height Equals: 60

Tried this:

settings the Right Section Insets to 100, but that only worked for a constant number of tags.

also found this post:

UITableView scrolling to last cell only displays half of the cell

but it's a different case (programmatically built tableview with manual scroll) and also a different language (obj-c)


Solution

  • So I set Min Spacing back to 0 and also Section Insets to 0

    I figured the best solution would be setting the spacing INSIDE the cell.

    so I went to the xib file, added a view container to wrap the label, and set the label's constraints to be 8 on the sides.

    this way - the collectionView "thinks" the cell is wider, and you get the space between the cells.

    enter image description here