0

enter image description here

The right column pictures get cut off. For example, the pink lion on the right should be basically symmetrical, but is obviously not. This is how I configure the imageCell.

func configureCellWithImage(image: Image){
    let iV = self.imageView
    iV.setImageWithURL(image.thumbURL)
    if(image.aspectRatio < 1.62){
        iV.contentMode = UIViewContentMode.ScaleAspectFit
    }else{
        iV.contentMode = UIViewContentMode.ScaleAspectFill
    }

}

And this is how I return the size of the cell.

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    let size = CGSize.init(width: screenSize.width/2 - 1, height: screenSize.width/2 * 1.62 - 1)
    return size
}

Help appreciated. Thank you.

EDIT:

I don't know why the UIView is there with the width of 201. It should be 159. How would I access this view? I should only have the CollectionView, imageCell and the UIImageView.

enter image description here

Latcie
  • 701
  • 1
  • 7
  • 21

3 Answers3

0

Try to increase value of right attribute in "section insets" of collection view in story board

Scale section of Collection View

Avim
  • 101
  • 1
  • 10
0

You have used ScreenSize in sizeForItemAtIndexPath method, this is wrong, you will use the collectionView width size, use my below code,

    func collectionView(collectionView : UICollectionView,layout collectionViewLayout:UICollectionViewLayout,sizeForItemAtIndexPath indexPath:NSIndexPath) -> CGSize
        {
            return CGSize(width: (self.collectionView!.frame.width/2)-5, height: ((self.collectionView!.frame.width/2) * 1.62) - 1)
        }

    func collectionView(collectionView: UICollectionView,
        layout collectionViewLayout: UICollectionViewLayout,
        insetForSectionAtIndex section: Int) -> UIEdgeInsets {
            return UIEdgeInsetsMake(0, 0, 0, 0)
    }

    func collectionView(collectionView: UICollectionView,
        layout collectionViewLayout: UICollectionViewLayout,
        minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
            return 0.0
    }

    func collectionView(collectionView: UICollectionView,
        layout collectionViewLayout: UICollectionViewLayout,
        minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
            return 0.0
    }

hope its helpful.

Iyyappan Ravi
  • 3,205
  • 2
  • 16
  • 30
  • Unfortunately, that didn't work. It looks like the compiler is creating another UIView. Please see edit on my OP. – Latcie Jun 09 '16 at 06:42
  • you will set the imageView in `UICollectionViewCell` and set constraints in ImageView, its automatically change the size in image, then use my code, its will work. – Iyyappan Ravi Jun 09 '16 at 07:11
0

So I found this post after searching more.

Autoresizing issue of UICollectionViewCell contentView's frame in Storyboard prototype cell (Xcode 6, iOS 8 SDK) happens when running on iOS 7 only

The solution was to put

self.contentView.frame = self.bounds;
Community
  • 1
  • 1
Latcie
  • 701
  • 1
  • 7
  • 21