首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将TopLeft和TopRight的UIView角改为圆角?

如何将TopLeft和TopRight的UIView角改为圆角?
EN

Stack Overflow用户
提问于 2015-01-20 04:47:02
回答 2查看 870关注 0票数 2

我想在我的UIView中使用圆角样式,下面是我的代码:

代码语言:javascript
运行
复制
UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:self.styleView1.bounds
                                               byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
                                                     cornerRadii:CGSizeMake(4, 4)];
CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
maskLayer1.frame = self.styleView1.bounds;
maskLayer1.path = maskPath1.CGPath;
self.styleView1.layer.borderWidth = 1;
[self.styleView1.layer setBorderColor:[[UIColor lightGrayColor] CGColor]];
self.styleView1.layer.mask = maskLayer1;

其效果如下:

墙角是空白的,就像Photoshop中的羽毛效果一样。

但我想要的是:

怎样才能实现呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-01-20 05:10:37

您可以将顶部视图的半径设置为下面的代码检查(how to set cornerRadius for only bottom-left,bottom-right and top-left corner of a UIView?)以供参考。

代码语言:javascript
运行
复制
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:yourView.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii:CGSizeMake(10.0, 10.0)];

CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
shapeLayer.frame = yourView.bounds;
shapeLayer.path  = path.CGPath;
yourView.layer.mask = shapeLayer;

你会被跟踪的。

票数 1
EN

Stack Overflow用户

发布于 2015-01-20 04:49:54

如果self是一个UIViewController或UISplitViewController,那么self没有边界,它是一个控制器。

试试这个:

代码语言:javascript
运行
复制
CGRect bounds = self.view.bounds;
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.styleView1.bounds
                                 byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
                                       cornerRadii:CGSizeMake(10.0, 10.0)];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = bounds;
maskLayer.path = maskPath.CGPath;
self.styleView1.layer.mask = maskLayer;
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28037920

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档