iOS 指定设置控件圆角

来源:互联网 发布:查重软件有哪些 编辑:程序博客网 时间:2024/05/19 15:25


这里使用button作为示例:

众所周知,设置控件的圆角使用layer.cornerRadius属性即可,但是这样设置成的结果是4个边角都是圆角类型。

下面指定设置某个角为圆角

//利用班赛尔曲线画角

            UIBezierPath *bezierPath = [UIBezierPathbezierPathWithRoundedRect:button.boundsbyRoundingCorners:(UIRectCornerBottomLeft |UIRectCornerBottomRight)cornerRadii:CGSizeMake(10,10)];

            CAShapeLayer *shapeLayer = [[CAShapeLayeralloc] init];

            shapeLayer.frame = button.bounds;

            shapeLayer.path = bezierPath.CGPath;

            button.layer.mask = shapeLayer;


typedef NS_OPTIONS(NSUInteger, UIRectCorner) {

    UIRectCornerTopLeft     = 1 <<0, //左上

    UIRectCornerTopRight    = 1 <<1, //右上

    UIRectCornerBottomLeft  = 1 <<2, //左下

    UIRectCornerBottomRight = 1 <<3, //右下

    UIRectCornerAllCorners  = ~0UL    //全角

};




1 0
原创粉丝点击