将圆角添加到UITableView的顶部? [英] Adding Rounded Corners to only top of UITableView?

查看:189
本文介绍了将圆角添加到UITableView的顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将圆角添加到我的UITableView的顶角但是问题是,使用下面的代码,它只是在我的整个UITableView上形成一个黑色层。我该如何解决这个问题?

I am trying to add rounded corners to only the top corners of my UITableView but the problem is, with the code below, it just makes a black layer over my whole UITableView. How would I fix this?

//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];


推荐答案

我认为制作背景视图的最佳方式表视图哪个视图有圆角顶部。它只是一个解决问题的解决方案。可能它会帮助你。

I think the best way to make a background view for the table view which view has rounded top corner.Its just a solution to solve the problem.May be it will help you.

这篇关于将圆角添加到UITableView的顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆