iPhone – Group UITableViews and images masking

Therefore, for the grouped UITableView, I want the image in the imageView placed in the topView of the UITableViewCell to look like this (from the iTunes application):

< p>Instead, I got this:

The part doesn’t seem to obscure the image view of the cell. Why not? I have tried everything I can think of. As far as I know, this is a swamp standard setting. UITableView is part of UITableViewController and there is no custom UITableViewCell.

Has anyone else encountered this ? Is there an easy way to customize UITableViewCells to achieve this? I tried Matt Gallagher’s code, but he didn’t cover up the image in the top (and bottom) row.

Hope it’s not obvious to me-but did you try to set imageView.clipsToBounds?

(It’s not like that, I just tried it.)

This is the hard way…

 #import 


cell.imageView.layer.masksToBounds = YES;
cell.imageView.layer.cornerRadius = 9.0;

< p>(At least it is set to “Retina” in 9.0 on my emulator.)

This will leave an image with four rounded corners, which is not what you want, but Halfway. Now, if you crop the image and then do a two-stage replacement, first replace the right edge of the image with rectangles (top right and bottom right), and then replace what you want with the small rectangle at the bottom left. Picky I know, but I don’t I think there is a simple answer.

I think the most appropriate approach may be to combine it into a UIImage, the corners you need are transparent, and then only apply special UIImage instead of normal in cellForRowAtIndexPath Image, if it is a group-first or group-last cell.

CGContextClipToMask looks like the one to be used.

So, for Grouped UITableView, I want the image in the imageView placed in the topView of the UITableViewCell to look like this (from the iTunes application):

Instead, I got this:

< p>This part does not seem to obscure the image view of the cell. Why not? I have tried everything I can think of. As far as I know, this is a swamp standard setting. UITableView is part of UITableViewController and there is no custom UITableViewCell.

Has anyone else encountered this ? Is there an easy way to customize UITableViewCells to achieve this? I tried Matt Gallagher’s code, but he didn’t cover up the image in the top (and bottom) row.

Hope it’s not obvious to me-but you try to set imageView.clipsToBounds?

(It’s not like that, I just tried it.)

This is the hard way…

 #import 


cell.imageView.layer.masksToBounds = YES;
cell.imageView.layer.cornerRadius = 9.0;

< p>(At least it is set to “Retina” in 9.0 on my emulator.)

This will leave an image with four rounded corners, which is not what you want, but Halfway. Now, if you crop the image and then do a two-stage replacement, first replace the right edge of the image with rectangles (top right and bottom right), and then replace what you want with the small rectangle at the bottom left. Picky I know, but I don’t I think there is a simple answer.

I think the most appropriate approach may be to combine it into a UIImage, the corners you need are transparent, and then only apply special UIImage instead of normal in cellForRowAtIndexPath Image, if it is a group-first or group-last cell.

CGContextClipToMask looks like the one to be used.

Leave a Comment

Your email address will not be published.