Rounded UIView using CALayers - only some corners - How?

后端 未结 14 2223
南方客
南方客 2020-11-22 13:53

In my application - there are four buttons named as follows:

  • Top - left
  • Bottom - left
  • Top - right
  • Bottom - right

Abov

14条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 14:25

    Stuarts example for rounding specific corners works great. If you want to round multiple corners like top left and right this is how to do it

    // Create the path (with only the top-left corner rounded)
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:imageview
                                                   byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight
                                                         cornerRadii:CGSizeMake(10.0, 10.0)];
    
    // Create the shape layer and set its path
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = imageview.bounds;
    maskLayer.path = maskPath.CGPath;
    
    // Set the newly created shape layer as the mask for the image view's layer
    imageview.layer.mask = maskLayer; 
    

提交回复
热议问题