0

I have a UITableView whose cells have an image from a URL placed in its imageView.

The image isn't square (is landscape), however it initially loads as a square in the manner in which contentMode is scaleAspectFill and setClipsToBounds is YES. So far so good.

However, when I touch down on the cell, the image "widens", that is, it retains the scaleAspect part, but now bleeds out to the right as if setClipsToBounds is NO.

The same behavior occurs if the row/cell goes out of view and comes back in recycled, in which case I have the image obtained from an in-memory cache rather than from the URL.

I've tried explicitly setting both contentMode and setClipsToBounds for the cell.imageView, but it seems to have no effect. Any advise? Thanks.

Before touchdown:

before touchdown

After touchdown (or recycle from cache):

after touchdown

Steven
  • 1,049
  • 2
  • 14
  • 32

2 Answers2

0

imageView cell property (same as other textLabel and detailTextLabel) changes its frame in layoutSubviews accordingly to image size. So you can reimplement layoutSubviews to have fixed frame rect. BTW, try TableKit library.

onegray
  • 5,105
  • 1
  • 23
  • 29
  • Thanks. Do you mean I have to subclass UITableViewCell, work with cells of that type, and override that class's layoutSubviews? – Steven Apr 26 '12 at 02:42
  • 1
    First, you need to disclose your authorship when promoting a project you wrote. The same rules apply as when you're promoting a product or website of your own (see the [FAQ](http://stackoverflow.com/faq#promotion) for details). Second, you should explain *why* someone should try it. Example code showing how it solves the problem in the question would do that. – Bill the Lizard Apr 29 '12 at 14:51
0

Heres a link to the correct answer if anyone is still looking for a solution: UIImageView in UITableViewCell changes size on touchDown

Its because you named it imageView, name it something like image_View and the problem is solved!

Community
  • 1
  • 1
MSU_Bulldog
  • 3,501
  • 5
  • 37
  • 73