Posts

Showing posts with the label layout

Image does not fit properly in collectionCell

Image
Clash Royale CLAN TAG #URR8PPP Image does not fit properly in collectionCell In Swift 3. My app has a table view and a detail view with is a view controller. Here I added a collection view. An array of images must be presented. The images adapt themselves beautifully if in portrait I check the content mode in scaler to fill. In ladscape it works in aspectFill. Vice-versa, the layout does not fit. I did the following in cellForItem At: func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = myCollection.dequeueReusableCell(withReuseIdentifier: "cellCollection", for: indexPath) as! CollectionViewCell cell.cellImage.image = UIImage(named: array[indexPath.item]) if UIDevice.current.orientation.isLandscape{ cell.cellImage.contentMode = .scaleAspectFill } else if UIDevice.current.orientation.isPortrait{ cell.cellImage.contentMode = .scaleToFill } return cell } I...