1

I display the data in a tableview
In Content Mode of image, I choose Aspect Fit
But I got something like this

with background.red
How to remove empty space around image?
I tried to find some answers, but unsuccessfully
Please help

When i use aspectFill

I use this code to show image from url
I use Kingfisher

 cell.image_of_new.kf.indicatorType = .activity
    cell.image_of_new.kf.setImage(
        with: url,
        placeholder: UIImage(named: "placeholderImage"),
        options: [
            .scaleFactor(UIScreen.main.scale),
            .transition(.fade(1)),
            .cacheOriginalImage
        ])
    {
        result in
        self.tableview.beginUpdates()
        self.tableview.endUpdates()
    }
Marshall
  • 141
  • 3
  • 9
  • there are a few options for this.. how is the image added? Do you have some padding. A good tip is to always first do image.backgroundColor = .red just to see its borders. And if you see its not on the edge, you have some padding somewhere. Do the same for the background View and add a color. it just helps to debug while designing – arvidurs May 22 '19 at 17:48
  • i updated question – Marshall May 22 '19 at 17:56
  • this will leave top and bottom spaces – Shehata Gamal May 22 '19 at 17:57
  • That helps. So where ever you are adding this view to the cell there is some padding left/right. If you want the image to fill the whole space using its aspect, use .aspectFill. But if I understood the question right, its about the left and right spacing? – arvidurs May 22 '19 at 18:05
  • Can you updated with code of the CollectionViewCell class. The one you register for the collectionView. Its hard to guess – arvidurs May 22 '19 at 18:08
  • When i use aspectFill, it not what i need – Marshall May 22 '19 at 18:11
  • i use tableview – Marshall May 22 '19 at 18:12
  • Please show the code of the Cell where you are adding the imageView. Doesn't matter if table view or collection view – arvidurs May 22 '19 at 18:17
  • 1
    @Marshall - numerous answers outhere... take a look at this one: https://stackoverflow.com/a/41155070/6257435 – DonMag May 22 '19 at 18:22

1 Answers1

1

Aspect fit is to designed to leave blank space if the image is a different shape than the frame into which you are drawing it.

The "aspect" part means it won't stretch the image to fit the target frame.

The "fit" part means it will be drawn so that every part of the source image fits into the destination frame. Nothing gets clipped.

Your target frame is tall and skinny (portrait) and your image is wide (landscape.) To draw it into the tall skinny frame without stretching or clipping, you will have blank space at the top and bottom.

By contrast, aspect fill will draw the image into the target rectangle without distorting the source image, but trim away parts of the source image.

Duncan C
  • 128,072
  • 22
  • 173
  • 272