Search code examples
iosswiftclip

How can I “clipToBottomBounds”?


clipsToBounds = true clips the bounds on all 4 sides.

I would like to clip the bottom bounds only, and allow overflow of the top, left and right bounds.

How would I go about doing that in Swift 4?


Solution

  • You can add masking layer with size much high on given side on which you want masking.

    You can use following code for masking only from bottom side.

    let maskingLayer = CALayer()
    maskingLayer.backgroundColor = UIColor.black.cgColor
    maskingLayer.frame = CGRectMake(0, 0, 0, 500); 
    
    myView.layer.mask = maskingLayer;
    

    You can change frame of maskingLayer to mask different sides that you want.