这个问题在这里已经有一个答案:>
iOS 7 TableView like in Settings App on iPad14个
自从引入iOS7以来,Apple( confirmed here)将删除UITableView的分组样式的单元格的圆角.不过,我相信有聪明的人在那里建立了解决办法.
自从引入iOS7以来,Apple( confirmed here)将删除UITableView的分组样式的单元格的圆角.不过,我相信有聪明的人在那里建立了解决办法.
请帮助我和许多其他iOS程序员,发布您的解决方法,以便在此线程中的iOS7中的UITableViewStyleGrouped中的单元格圆角.这将是非常感谢!
解决方法
只需在代码中添加以下UITableView代理方法即可.它真的帮助我像iOS7中的表视图一样的问题.尝试以下代码,可能也解决了您的问题:
- (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,CGRectGetMinX(bounds),CGRectGetMaxY(bounds)); CGPathAddArcToPoint(pathRef,CGRectGetMinY(bounds),CGRectGetMidX(bounds),cornerRadius); CGPathAddArcToPoint(pathRef,CGRectGetMaxX(bounds),CGRectGetMidY(bounds),cornerRadius); CGPathAddLineToPoint(pathRef,CGRectGetMaxY(bounds)); addLine = YES; } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) { CGPathMoveToPoint(pathRef,CGRectGetMinY(bounds)); CGPathAddArcToPoint(pathRef,CGRectGetMaxY(bounds),CGRectGetMinY(bounds)); } else { CGPathAddRect(pathRef,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; } } }