首页 > 移动平台 > 详细

iOS开发设置view某几个角为圆角

时间:2020-01-02 16:17:42      阅读:144      评论:0      收藏:0      [点我收藏+]
我们知道设置四个角都为圆角很简单,创建一个view,设置其layer.cornerRadius即可,代码如下:
    UIView *testview = [[UIView alloc] init];
    testview.layer.cornerRadius = 10;
    [self.view addSubview: testview];

 

其实指定圆角也是通过view的layer属性来设置的,我通过设置控件的上面两个角为圆角来举例,代码如下:
 
 UIView *testview = [[UIView alloc] init];
    [self.view addSubview: testview];

    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: testview.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10,10)];
    //创建 layer
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = testview.bounds;
    //赋值
    maskLayer.path = maskPath.CGPath;
    testview.layer.mask = maskLayer;

 

首先创建view,然后单独设置其layer的方法,再将其赋值给view的layer属性即可,通过方法里面的参数UIRectCornerTopLeft,UIRectCornerTopRight我们便可以看出这是设置其左上角以及右上角为圆角,在cornerRadii:中设置圆角尺寸即可实现我们想要的效果。

 

 

 

 

iOS开发设置view某几个角为圆角

原文:https://www.cnblogs.com/-yun/p/12133495.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!