Use of different mode like "Scale To Fill","Aspect Fit",""Aspect Fill" to handell UIImageView inside UITableViewCell

12,053

Solution 1

You have an option named Clip subviews on your table view cell. Check that it's activated, and it should be good.

Solution 2

As per your description Your constraints are all set correct.

Aspect Fill will draw the entire inside the imageView by maintaining the image's aspect ratio. If the image is larger than the imageView's dimension the image overflows. In such cases you need to activate the "Clips subview" option in the attribute inspector of your imageView.

Go to your cell's imageView attribute inspector in storyboard/xib. Under the "Drawing" section choose "Clips subviews" as true.

This will make the superView clip its subviews. In your case cell's contentView is the superView and imageView the subview.

Solution 3

You need to enable clip subviews property for imageview, cell's contentview and cell. One more thing, I saw that while you added constraints, you added constraints with margin.. So, remove old constraints and add again new constraints with disabling Constraints to margin..

Let me know if it helps. :)

Share:
12,053
Nischal Hada
Author by

Nischal Hada

Updated on June 04, 2022

Comments

  • Nischal Hada
    Nischal Hada almost 2 years

    I have used UIImageView inside the UITableViewCell and it will fill the contentView.I have try different mode like "Scale To Fill","Aspect Fit",""Aspect Fill" to handell UIImageView inside UITableViewCell. UIImageView inside UITableViewCell is running out of the screen in Aspect Fill. I have set constraints for the image as shown below enter image description here

    It works fine as below

    enter image description here

    But when image size is too large it shows problem as below that it goes outside the cell boundary

    enter image description here

    I have use Aspect Fill as shown below image

    enter image description here

    when I use Aspect Fit I got this problem

    enter image description here

    When I use Scale To Fill I got this problem

    enter image description here

    In Aspect Fit and Scale To Fill I got margin in left and right as shown above

    below link doesnt address my problem so its not duplicate

    UIImageView inside UITableViewCell does not get updated

    Resizing UIImageView inside a UITableViewCell

    iOS 8 - AutoLayout issue - UIImageView inside UITableViewCell ignoring width constraints

  • Nischal Hada
    Nischal Hada almost 9 years
    Its not that problem is on cell
  • Samir
    Samir almost 9 years
    Okay, What happen when you set Aspect Fill ? You haven't shown it. And clip subviews is in Attribute inspector for that image view
  • Nischal Hada
    Nischal Hada almost 9 years
    My question is about Aspect Fill. check the question dude
  • Tejvansh
    Tejvansh almost 9 years
    Go to your cell's xib, and select the imageview, and follow this stackoverflow.com/questions/6715341/…
  • Samir
    Samir almost 9 years
    Lolz, Dude. This is the way it should work. In Aspect fill it will try to maintain Aspect ration of Image(Width and height) and In scale to fill (it will scale whatever imagesize it get). However try clip subview.
  • Nischal Hada
    Nischal Hada almost 9 years
    Ok dude.. I will try that
  • Tejvansh
    Tejvansh almost 9 years
    If my answer helped you, please mark as correct, so other know which answer to follow.. :)
  • Vidhyanand
    Vidhyanand almost 9 years
    At XIB you will have editor option on tool bar on top. Click on editor --> Pin --> Width/Height. Or you can set constraints using above link. See my updated answer for link...!