将圆angular添加到只有UITableView的顶部?

我想添加圆angular只有我的UITableView的顶部angular落,但问题是,与下面的代码,它只是在我的整个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]; 

我认为最好的办法是为表格视图做一个背景视图,哪个视图有圆angular的顶点,它只是解决问题的一个解决scheme,可能会对你有帮助。

下面的代码适用于我的导航栏,只是改变第一行,把你的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;