Setting BackgroundColor highlighting style for UITableViewCell Grouped

I want to set the background color of a UITableViewCell when it is highlighted in a grouped table view. The code I'm using now gives the results. Can someone please tell me the correct way to do this in order to support the rounded corners of a uitableviewcell?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.bounds] ; cell.selectedBackgroundView.backgroundColor = coolBlue ; } 

Updated code:

 cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.bounds]; cell.selectedBackgroundView.backgroundColor = coolBlue; UIBezierPath *rounded = [UIBezierPath bezierPathWithRoundedRect:cell.selectedBackgroundView.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(8.0f, 8.0f)]; CAShapeLayer *shape = [[CAShapeLayer alloc] init]; [shape setPath:rounded.CGPath]; cell.selectedBackgroundView.layer.mask = shape; rounded = nil; shape = nil; 

enter image description here

Update:

enter image description here

+7
objective-c cocoa-touch uitableview
source share
2 answers

Using the Bazier Path, you can give two upper or lower two or any numbers of angular radius (obviously, from 4).

Here I set the upper left and upper right corner for the cell background:

 UIBezierPath *rounded = [UIBezierPath bezierPathWithRoundedRect:cell.selectedBackgroundView.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(8.0f, 8.0f)]; CAShapeLayer *shape = [[CAShapeLayer alloc] init]; [shape setPath:rounded.CGPath]; cell.selectedBackgroundView.layer.mask = shape; rounded = nil; shape = nil; // you can change the code as per your need 

And now you just want to set the angle for the first and last background of the cell.

And don't forget to add the QuartzCore Framework to your project and #import <QuartzCore/QuartzCore.h> to your class.

you can change the textlable text color when highlighting with:

 cell.textLabel.highlightedTextColor = [UIColor blackColor]; 
+7
source share

All Articles