Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 720
Nischal Hada Avatar asked May 18 '15 11:05

Nischal Hada


3 Answers

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

like image 126
Cyrille Avatar answered Sep 22 '22 17:09

Cyrille


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.

like image 20
shashank ch Avatar answered Sep 21 '22 17:09

shashank ch


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

like image 20
Tejvansh Avatar answered Sep 23 '22 17:09

Tejvansh