How to create rounded UIButton with top-left & bottom-left corner radius only

前端 未结 2 429
余生分开走
余生分开走 2021-01-19 07:28

I need to create a button with top-left & bottom-left corner radius like this one . I tried by creating the following extension that was taken from one of stackoverflow

2条回答
  •  既然无缘
    2021-01-19 08:07

    Here is how you can do it:

    CGRect maskRect = CGRectMake(0.0, 0.0, CGRectGetWidth(<#something here#>), CGRectGetHeight(<#something here#>));
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:maskRect
                                               byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerTopLeft)
                                                     cornerRadii:CGSizeMake(<#corner radius#>, <#corner radius#>)];
    maskLayer.path = path.CGPath;
    self.layer.mask = maskLayer;
    

提交回复
热议问题