Ios 是否仅将圆角添加到UITableView的顶部?

Ios 是否仅将圆角添加到UITableView的顶部?,ios,uitableview,calayer,Ios,Uitableview,Calayer,我试图只在UITableView的顶部添加圆角,但问题是,下面的代码只会在整个UITableView上形成一个黑色层。我该如何解决这个问题 //Rounded Corners for top corners of UITableView UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:thetableView.bounds

我试图只在UITableView的顶部添加圆角,但问题是,下面的代码只会在整个UITableView上形成一个黑色层。我该如何解决这个问题

//Rounded Corners for top corners of UITableView
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:thetableView.bounds 
                                               byRoundingCorners:UIRectCornerTopLeft
                                                     cornerRadii:CGSizeMake(10.0, 10.0)];
UIBezierPath *maskPath2 = [UIBezierPath bezierPathWithRoundedRect:thetableView.bounds 
                                               byRoundingCorners:UIRectCornerTopRight
                                                     cornerRadii:CGSizeMake(10.0, 10.0)];
// Create the shape layer and set its path
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = thetableView.bounds;
maskLayer.path = maskPath.CGPath;

CAShapeLayer *maskLayer2 = [CAShapeLayer layer];
maskLayer.frame = thetableView.bounds;
maskLayer.path = maskPath2.CGPath;

// Set the newly created shape layer as the mask for the image view's layer
[thetableView.layer addSublayer:maskLayer];
[thetableView.layer addSublayer:maskLayer2];

我认为为具有圆角的表视图创建背景视图的最佳方法。这只是解决问题的一个解决方案。可能会对您有所帮助。

以下代码适用于导航栏,只需更改第一行并放置您的self.tableView:

CALayer *capa = [self.navigationController navigationBar].layer;
[capa setShadowColor: [[UIColor blackColor] CGColor]];
[capa setShadowOpacity:0.85f];
[capa setShadowOffset: CGSizeMake(0.0f, 1.5f)];
[capa setShadowRadius:2.0f];  
[capa setShouldRasterize:YES];


//Round
CGRect bounds = capa.bounds;
bounds.size.height += 10.0f;    //I'm reserving enough room for the shadow
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bounds 
                                               byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
                                                     cornerRadii:CGSizeMake(10.0, 10.0)];

CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = bounds;
maskLayer.path = maskPath.CGPath;

[capa addSublayer:maskLayer];
capa.mask = maskLayer;

这将是同一个问题。我的问题是关于任何UIView或其子类的。所以我需要弄清楚这一点。检查它可能会对你有所帮助。哦,我不应该做addSublayer,我应该只设置CCLayer的mask属性。那么,如何在一个掩码中添加多个UIRextConner呢?我不知道wtf是
UIRextConner
?如果你能给我一个你的要求的例子,那将对我非常有帮助…它可以是图像。对不起,我是说图像。我只是尝试将角半径应用于视图,但仅应用于顶部角,而不是底部2。但我现在的问题是,代码用黑色层覆盖了视图!