Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can add a category on UIImage and include this method:</p> <pre><code>// Return the image, but with rounded corners. Useful for masking an image // being used in a UITableView which has grouped style - (UIImage *)imageWithRoundedCorners:(UIRectCorner)corners radius:(CGFloat)radius { // We need to create a CGPath to set a clipping context CGRect aRect = CGRectMake(0.f, 0.f, self.size.width, self.size.height); CGPathRef clippingPath = [UIBezierPath bezierPathWithRoundedRect:aRect byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)].CGPath; // Begin drawing // Start a context with a scale of 0.0 uses the current device scale so that this doesn't unnecessarily drop resolution on a retina display. // Use `UIGraphicsBeginImageContextWithOptions(aRect.size)` instead for pre-iOS 4 compatibility. UIGraphicsBeginImageContextWithOptions(aRect.size, NO, 0.0); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextAddPath(context, clippingPath); CGContextClip(context); [self drawInRect:aRect]; UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return croppedImage; } </code></pre> <p>Then when you're configuring your cells, in the table view controller, call something like:</p> <pre><code>if ( *SINGLE_ROW* ) { // We need to clip to both corners cell.imageView.image = [image imageWithRoundedCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft) radius:radius]; } else if (indexPath.row == 0) { cell.imageView.image = [image imageWithRoundedCorners:UIRectCornerTopLeft radius:radius]; } else if (indexPath.row == *NUMBER_OF_ITEMS* - 1) { cell.imageView.image = [image imageWithRoundedCorners:UIRectCornerBottomLeft radius:radius]; } else { cell.imageView.image = image; } </code></pre> <p>but replace the SINGLE_ROW etc with real logic to determine whether you've got a single row in a section, or it's the last row. One thing to note here, is that I've found (experimentally) that the radius for a group style table is 12, which works perfectly in the simulator, but not on an iPhone. I've not been able to test it on a non-retina device. A radius of 30 looks good on the iPhone 4 (so I'm wondering if this is an image scale thing, as the images I'm using are from the AddressBook, so don't have an implied scale factor). Therefore, I've got some code before this that modifies the radius...</p> <pre><code>CGFloat radius = GroupStyleTableCellCornerRadius; if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] &amp;&amp; [[UIScreen mainScreen] scale] == 2){ // iPhone 4 radius = GroupStyleTableCellCornerRadiusForRetina; } </code></pre> <p>hope that helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload