Created
May 10, 2012 10:52
-
-
Save chaudum/2652397 to your computer and use it in GitHub Desktop.
Correctly rounded images in UITableViewCell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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