2

In my app, I have upload controller and a feed controller.

In the upload controller the image looks like this: Image Here

In the feed controller the image looks like this: Image here

As you can see, the image is stretched. Why is that?

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell: CollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CollectionViewCell

        cell.layer.borderWidth = 0.75
        cell.layer.cornerRadius = 3
        let myColor : UIColor = UIColor(red: 0.0, green: 0.0, blue:0.0, alpha: 0.55)
        cell.backgroundColor = UIColor.whiteColor()
        cell.layer.borderColor = myColor.CGColor

        let post = self.arrayOfDetails[indexPath.row]
        cell.imageText.text = post.text
        cell.uploadedTimeLabel.text = post.CreatedAt.timeAgo

        cell.imageView.setImageWithUrl(NSURL(string: post.image)!, placeHolderImage: UIImage(named: "Placeholder"))

        return cell
    }

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {

        return CGSizeMake(UIScreen.mainScreen().bounds.size.width - 10, 300)
    }

I tried removing the sizeForItemAtIndexPath, that made the image fits good, but the cell does not fits the screen:

Any suggestions?

Undo
  • 25,519
  • 37
  • 106
  • 129
Kim Phoe
  • 25
  • 9

1 Answers1

0

In your collectionViewCell, if you have made it using storyboard, select the image and set its mode to "AspectFit"

This post may help you to understand about Modes

enter image description here

Community
  • 1
  • 1
Fayza Nawaz
  • 2,256
  • 3
  • 26
  • 61
  • I tried this and that worked. But the problem now it that it made the imageView smaller. I have set the same width and height in the feed controller and the upload controller in storyboard, but on the device, it is smaller: http://s16.postimg.org/ch4cavbnp/Screen_Shot_2015_11_20_at_00_42_26.png – Kim Phoe Nov 19 '15 at 23:44
  • 1
    It is not making your imageView smaller. It's just fitting the image and rest of the space (that's white) is background of your view. – Fayza Nawaz Nov 19 '15 at 23:46
  • But in the upload controller it is not that small. In the upload controller it is this big: http://i.stack.imgur.com/NN0zi.jpg – Kim Phoe Nov 19 '15 at 23:48
  • Are you sure that size of your uploader and cell is same? In pictures, i feel that uploader size > cell's size (Your uploader is covering the screen, and there're app 2 cells on the screen) – Fayza Nawaz Nov 19 '15 at 23:50
  • Yes, both the imageView´s are 304x304 - http://s27.postimg.org/ooyg8sw0j/Screen_Shot_2015_11_20_at_00_52_01.png – Kim Phoe Nov 19 '15 at 23:52
  • Probably, you're telling me the sizes of imageViews in both containers (your uploader and your cell). But i'm talking about the size of imageView in your uploader and the size of your cell. Confirm that. If these 2 are same, then there must be no issue – Fayza Nawaz Nov 20 '15 at 00:01
  • Hm, the size of my imageView in uploader is 304x304, and the size of my cell is 320x413. – Kim Phoe Nov 20 '15 at 00:03