Search code examples
swiftuicollectionviewcell

How to arrange collectionview cells closely according to text in swift


I have given collectionview constraints

 height = 50, leading = trailing = top = 10

i have taken label inside containerview in cell

cell containerview constraints

 bottom = top = 5, horizontal center

label constraints with containerview

 leading = trailing = top = bottom = 5

code in didload:

   let serviceLayout = UICollectionViewFlowLayout()
    serviceLayout.minimumInteritemSpacing = 0
    serviceLayout.minimumLineSpacing = 0
    serviceLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
          self.servicesCollectionView.collectionViewLayout = serviceLayout

i am getting like this i need one near by another

enter image description here

i need like this

enter image description here

how do i get collectionview cells near by one another, pls do help


Solution

  • Select your collection view in storyboard

    • Go to size inspector
    • Set scrollview indicator insets left and right as follows

    enter image description here