Hello!I've noticed a very strange behavior with UICollectionViewCell.I am currently using XCode 11.I have an UICollectionView and a simple UICollectionViewCell with an imageview inside.The Imageview has four constraints Trailing, Leading, Bottom and Space to Superview.The delegates are implemented:extension ViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return data.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collCell", for: indexPath)
cell.backgroundColor = data[indexPath.row]
return cell
}
}
extension ViewController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 200.0, height: 200.0)
}
}Thisfunc collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 200.0, height: 200.0)
}should create cells with the size 200x200. Which is working fine unless i add a image to the imageview within UICollectionViewCell.Then the cell gets the size of that image and is no longer 200x200func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collCell", for: indexPath)
cell.backgroundColor = data[indexPath.row]
cell.imageView.image = UIImage(named: "test")
return cell
}How to prevent the imageview to resize the uicollectionviewcell?Thank you
Selecting any option will automatically load the page