Workaround for rounded corners of grouped UITableView, iOS7
Just add following UITableView delegate method in your code. It's really helped me to same issue like you for Table view in iOS7. Try following code taken from this answer by jvanmetre, may be it's also solved your problem:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(tintColor)]) {
if (tableView == tblProfileDetails) { // self.tableview
CGFloat cornerRadius = 5.f;
cell.backgroundColor = UIColor.clearColor;
CAShapeLayer *layer = [[CAShapeLayer alloc] init];
CGMutablePathRef pathRef = CGPathCreateMutable();
CGRect bounds = CGRectInset(cell.bounds, 5, 0);
BOOL addLine = NO;
if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);
} else if (indexPath.row == 0) {
CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
addLine = YES;
} else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
} else {
CGPathAddRect(pathRef, nil, bounds);
addLine = YES;
}
layer.path = pathRef;
CFRelease(pathRef);
layer.fillColor = [UIColor colorWithWhite:1.f alpha:0.8f].CGColor;
if (addLine == YES) {
CALayer *lineLayer = [[CALayer alloc] init];
CGFloat lineHeight = (1.f / [UIScreen mainScreen].scale);
lineLayer.frame = CGRectMake(CGRectGetMinX(bounds)+5, bounds.size.height-lineHeight, bounds.size.width-5, lineHeight);
lineLayer.backgroundColor = tableView.separatorColor.CGColor;
[layer addSublayer:lineLayer];
}
UIView *testView = [[UIView alloc] initWithFrame:bounds];
[testView.layer insertSublayer:layer atIndex:0];
testView.backgroundColor = UIColor.clearColor;
cell.backgroundView = testView;
}
}
}
iOS 7 UITableViewStyleGrouped missing rounded corners and cell row width fill view size
iOS 7 is Borderless. Rounded corners are no longer available in iOS 7. Apple removed this feature. I am currently working with iOS 7 and had a discussion with apple support guys. They confirmed that this is no more supported. You can see the Settings app for an example — the table view there is group style.
Rounded corners in a UITableView (iOS7)
Your UITableview
contains UIView
, so just use this below lines of code for making it rounded corners.
Also write this below line of code inside your tableview methods
//If iOS version < 10
For Objective-C:
cell.contentView.layer.cornerRadius = 5;
cell.contentView.layer.masksToBounds = YES;
For Swift:
cell.contentView.layer.cornerRadius = 5
cell.contentView.layer.masksToBounds = true
//If iOS version >= 10
For Objective-C:
cell.layer.cornerRadius = 5;
cell.layer.masksToBounds = YES;
For Swift:
cell.layer.cornerRadius = 5
cell.layer.masksToBounds = true
Note: No need to import QuartzCore framework
explicitly.
changing corner radius of uitableview grouped in iOS6
You can change de backgroundView of the TableViewCell, create a subclass of UIView and change the layer class:
@interface BackgroundView : UIView
@end
@implementation BackgroundView
+ (Class)layerClass
{
return [CAShapeLayer class];
}
@end
later in cellForRowAtIndexPath you do something like this:
static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
CGRect frame = cell.backgroundView.frame;
cell.backgroundView = [[BackgroundView alloc] initWithFrame:frame];
CGFloat corner = 20.0f;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:cell.backgroundView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(corner, corner)];
CAShapeLayer *shapeLayer = (CAShapeLayer *)cell.backgroundView.layer;
shapeLayer.path = path.CGPath;
shapeLayer.fillColor = cell.textLabel.backgroundColor.CGColor;
shapeLayer.strokeColor = [UIColor lightGrayColor].CGColor;
shapeLayer.lineWidth = 1.0f;
return cell;
Results this:
You can modify the corners you want or create another path.
I hope it helps.
Related Topics
How to Dynamically Format a Number to Have Commas in a Uitextfield Entry
Detect Which App Is Currently Running on iOS Using Sysctl
Firebase Cocoapods Installation Not Working
(iOS + Storekit) How to Detect When I'm in the Sandbox
Swift: Custom Camera Save Modified Metadata with Image
Ios6 Simulator Mkmapkit "Couldn't Find Default.Styleproto in Framework"
Is There a Practical Way to Compress Nsdata
Difference Between Completion Handler and Blocks:[Ios]
Observing Change in Frame of a Uiview During Animation
How to Disable Arc for a Single File in Xcode 5
How to Tell If Blocks in Loop All Have Completed Executing
Scanning Barcode or Qr Code in Swift 3.0 Using Avfoundation
Uicollectionview Multiple Sections and Headers
How to Detect a Dual Core CPU on iOS
Save Eventually on Pfobject with Pffile (Parse Local Datastore)
How to Detect an iOS App Installed or Upgraded
External Framework File/File.H (Parse/Parse.H) File Not Found