I have collectionView like this
I’m calling different 3 xib files to cells like this
collectionView.register(UINib(nibName: "OfficialVehicleHeader", bundle: nil), forCellWithReuseIdentifier: "OfficialVehicleHeaderCell")
collectionView.register(UINib(nibName: "OfficialVehicleMedium", bundle: nil), forCellWithReuseIdentifier: "OfficialVehicleMediumCell")
collectionView.register(UINib(nibName: "OfficialVehicleBottom", bundle: nil), forCellWithReuseIdentifier: "OfficialVehicleBottomCell")
My collectionView layout code
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .vertical
collectionView.setCollectionViewLayout(layout, animated: true)
layout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
In the xib file i set constraint (leading, trailing, bottom, top as 0) in addition height constraint. The height is running awesome no problem but i don’t want to set width constraint. Because there is different between screens
Where did i mistake ?
2
Answers
I solved the problem. I need to set width constraint but i don't want to set. I solve this way
Go to xib file and set width constraint
Go to size inspector and select that you created width constraint
Set identifier for example "myConstraint"
Open your cell file and define IBOutlet
I added image that i mentioned
You have to set leading and trailing it will set width according to devices width. But don’t forget to make your collection views constraints to be resizable.
Here is my sample code on how to do it:
layout settings:
Cells constraints to be resizable: