我尝试使用以下代码,但没有运气。有人知道如何在iOS 6中执行此操作吗?我不想创建自定义单元。
self.tableView.layer.cornerRadius = 5.0f;
[self.tableView setClipsToBounds:YES];
编辑:
看来实际发生的是此代码正在为整个 View 而不是每个UITableViewSection创建一个拐角半径。这有意义吗?
我也尝试过
[cell.layer setCornerRadius:3.0];
但也没有运气。我的UITableView的角落仍然完全相同。 最佳答案
您可以更改TableViewCell的backgroundView,创建UIView的子类并更改图层类:
@interface BackgroundView : UIView
@end
@implementation BackgroundView
+ (Class)layerClass
{
return [CAShapeLayer class];
}
@end
稍后在cellForRowAtIndexPath中,您将执行以下操作:
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;
结果如下:
您可以修改所需的角或创建其他路径。
希望对您有所帮助。
关于ios - 更改iOS6中分组的uitableview的拐角半径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18095223/