5
votes

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

5
Have you tried to set UIImageView's different mode like "Scale To Fill","Aspect Fit",""Aspect Fill" etc.?iPhone
Yes correct!!! @iPhoneiGatiTech
I have used aspect fillNischal Hada
Please try out other UIImageView modes as well!!Rashmi Ranjan mallick
You need to enable clips to bounds property for imageview, cell's contentview and cell. I saw that while adding constraints, you set it with margin.. So, remove old constraints and again new constraints with disabling Constraints to margin.. Let me know if it helps. :)Tejvansh

5 Answers

4
votes

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

2
votes

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.

1
votes

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. :)

0
votes

I guess there is no issue in cell, Its in Tableview.
Set constraints to your Tableview in which this cell is used.
It will work.

0
votes

Set width and height constraints for UIImageView

Remove other constraints and set below constraints to imageview...!

UIImageView --> Editor --> Pin --> Width

UIImageView --> Editor --> Pin --> Height

Refer

https://developer.apple.com/library/ios/recipes/xcode_help-IB_auto_layout/chapters/pin-constraints.html

Hope it fix the issue..!