5

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

Community
  • 1
  • 1
Nischal Hada
  • 3,230
  • 3
  • 27
  • 57

5 Answers5

4

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

Cyrille
  • 25,014
  • 12
  • 67
  • 90
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.

1

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

Tejvansh
  • 676
  • 4
  • 9
  • Go to your cell's xib, and select the imageview, and follow this http://stackoverflow.com/questions/6715341/why-is-my-uiview-subview-not-rendering-within-the-parent-code-attached – Tejvansh May 18 '15 at 12:06
  • If my answer helped you, please mark as correct, so other know which answer to follow.. :) – Tejvansh May 18 '15 at 12:22
0

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.

Samir
  • 902
  • 9
  • 23
  • Its not that problem is on cell – Nischal Hada May 18 '15 at 11:39
  • Okay, What happen when you set Aspect Fill ? You haven't shown it. And clip subviews is in Attribute inspector for that image view – Samir May 18 '15 at 12:01
  • My question is about Aspect Fill. check the question dude – Nischal Hada May 18 '15 at 12:05
  • 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. – Samir May 18 '15 at 12:11
0

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..!

Vidhyanand
  • 5,369
  • 4
  • 26
  • 59
  • 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...! – Vidhyanand Jun 08 '15 at 06:34