1

I'm using drawRect: in my UITableViewCell subclass for the rendering performance when scrolling; everything on the cell (text and graphics) is rendered in drawRect:. On the new iPad's retina display, the cell appears very blurry.

For comparison, here is a screenshot with showing both the cells (on the top) and another equally sized image on the bottom. The difference between the quality of the bottom image and of the cells is stark.

Screenshot taken on iPad with retina display

This is on a physical device, not the simulator. I've verified that the UIImage instances I'm using have a scale of 2; the user's avatar images are being loaded from the web, so it's not an issue of an @2x suffix. The "Awesome" image is the same asset loaded from the main bundle. Further, the text itself is blurry.

I've tried different options of antialiasing to no effect. I've also tried setting the contentScaleFactor of my view and the contentScale of my view's layer to [[UIScreen mainScreen] scale] but it doesn't help either.

Any suggestions?

Edit:

Here's a snippet of the drawRect: method responsible for rendering the user avatar. _avatar is an instance variable and addRoundedRectToPath() just clips a corner radius of 5 points off of the context's path.

{
    CGContextSaveGState(context);

    addRoundedRectToPath(context, avatarFrame, 5, 5);
    CGContextClip(context);

    [_avatar drawInRect:avatarFrame];

    CGContextRestoreGState(context);
}

The text of the comment is rendered in a similar way:

[[UIColor whiteColor] set];
[_body drawInRect:textRect withFont:kPXCompositePhotoCommentCellBodyFont];

I'm deploying to iOS 5.0 with a 5.1 base SDK using Xcode 4.3.2.

Ash Furrow
  • 12,391
  • 3
  • 57
  • 92
  • Can you add some source code to show how you're handling this in -drawRect:? It very much looks like the sort of thing that would happen following a non-scaled UIGraphicsCreateImageContext() to perform offscreen rendering, but beyond that is hard to diagnose. – Jim Dovey Mar 22 '12 at 16:00
  • I've added some sample code - is there anything special I need to set in my graphics context to indicate that it should render with the higher pixel density? – Ash Furrow Mar 22 '12 at 16:08
  • I don't see anything suspect in there so far. Do you do anything else with the current context at this point? Also, what's on the stack— is this a plain -drawRect: call, or are you doing some trick to get flattened cell images, similar to the one Loren Brichter used in Tweetie back in the day? Perhaps look at the context's CTM/scale to see what's happening at the CG level? – Jim Dovey Mar 22 '12 at 16:12
  • No image-flattening; I'm just letting the system call `drawRect:` for me. The only thing I'm doing with the context is adding rounded corners, but the problem persists both if I remove those and on the text, whose context is untouched. – Ash Furrow Mar 22 '12 at 16:28
  • You're drawing in the cell's view, or in the cell's contentView's view? Or a subview of that? – Jim Dovey Mar 22 '12 at 17:22

1 Answers1

4

Have you set the view's layer to want rasterization? This is an opt in thing, and sometimes it's used as a trick to speed up cell performance. But improperly used it can result in ugly layers.

jbrennan
  • 11,943
  • 14
  • 73
  • 115
  • Sweet! It was actually the layer that contained the cell's table view. – Ash Furrow Mar 22 '12 at 17:47
  • Nice - that helped me. I needed to add the raster code to my container view for the tableview. [_uiv_tableContainer.layer setRasterizationScale:[[UIScreen mainScreen] scale]]; [_uiv_tableContainer.layer setShouldRasterize:YES]; – malaki1974 Aug 21 '13 at 19:34