Skip to content

Instantly share code, notes, and snippets.

@d-amend
Created December 4, 2012 16:51
Show Gist options
  • Save d-amend/4206103 to your computer and use it in GitHub Desktop.
Save d-amend/4206103 to your computer and use it in GitHub Desktop.
Selecting UITableViewCells in grouped UITableViews with custom color or view
#import <QuartzCore/QuartzCore.h>
@implementation CustomTableViewController
-(void)setSelectionViewForCell:(UITableViewCell*)cell withRoundedRectCorners:(UIRectCorner)rectCorners
{
CGRect cellRect = CGRectMake(0, 0, cell.bounds.size.width-18, cell.bounds.size.height);
UIView *view = [[UIView alloc] initWithFrame:cellRect];
if (rectCorners != 0) { //we need rounded corners, beginning or end of a tableViewSection
UIBezierPath * maskPath = [UIBezierPath bezierPathWithRoundedRect:cellRect byRoundingCorners:rectCorners cornerRadii:CGSizeMake(10.f, 10.f)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = cellRect;
maskLayer.path = maskPath.CGPath;
view.layer.mask = maskLayer;
}
[view setBackgroundColor:[UIColor redColor]];
[cell setSelectedBackgroundView:view];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment