如何设置cornerRadius仅UIView的左上角和右上角? [英] how to set cornerRadius for only top-left and top-right corner of a UIView?
本文介绍了如何设置cornerRadius仅UIView的左上角和右上角?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法只为UIView的左上角和右上角设置cornerRadius?
Is there a way to set cornerRadius for only top-left and top-right corner of a UIView?
编辑:
我试过下面的,但它最终没有看到视图了。下面的代码有什么问题?
I tried the following, but it end up not seeing the view anymore. Anything wrong with the code below?
UIView *view = [[UIView alloc] initWithFrame:frame];
CALayer *layer = [CALayer layer];
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRoundedRect:frame byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) cornerRadii:CGSizeMake(3.0, 3.0)];
layer.shadowPath = shadowPath.CGPath;
view.layer.mask = layer;
推荐答案
Swift代码示例: http://stackoverflow.com/a/35621736/308315
Swift code example here: http://stackoverflow.com/a/35621736/308315
不直接。您必须:
- 创建
CAShapeLayer
- 基于
view.bounds 将
路径
设置为CGPathRef
code>,但只有两个圆角(可能使用+ [UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:]
) - 将
view.layer.mask
设为CAShapeLayer
- Create a
CAShapeLayer
- Set its
path
to be aCGPathRef
based onview.bounds
but with only two rounded corners (probably by using+[UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:]
) - Set your
view.layer.mask
to be theCAShapeLayer
这篇关于如何设置cornerRadius仅UIView的左上角和右上角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文