How to set cornerRadius for only top-left and top-right corner of a UIView?

后端 未结 26 3505
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 06:14

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

26条回答
  •  生来不讨喜
    2020-11-22 07:05

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

提交回复
热议问题