Skip to content

Instantly share code, notes, and snippets.

@chaudum
Created May 10, 2012 10:52
Show Gist options
  • Save chaudum/2652397 to your computer and use it in GitHub Desktop.
Save chaudum/2652397 to your computer and use it in GitHub Desktop.
Correctly rounded images in UITableViewCell
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
UIRectCorner cornerDef;
if (indexPath.row == 0) {
cornerDef = UIRectCornerTopLeft|UIRectCornerTopRight;
} else if (indexPath.row == 1) {
cornerDef = UIRectCornerBottomLeft|UIRectCornerBottomRight;
}
CAShapeLayer *maskLayer = [CAShapeLayer layer];
UIBezierPath *roundedPath = [UIBezierPath bezierPathWithRoundedRect:cell.bounds
byRoundingCorners:cornerDef cornerRadii:CGSizeMake(9.0f, 9.0f)];
maskLayer.fillColor = [[UIColor whiteColor] CGColor];
maskLayer.backgroundColor = [[UIColor clearColor] CGColor];
maskLayer.path = [roundedPath CGPath];
[cell.imageView.layer setMask:maskLayer];
[cell.imageView.layer setMasksToBounds:YES];
[cell.imageView setNeedsDisplay];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment