-2

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?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Jim
  • 55
  • 1
  • 7

1 Answers1

1

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.

Mehul Thakkar
  • 12,440
  • 10
  • 52
  • 81
  • Thank you. I didn't know that "masking layers" existed. This seems to be exactly what I need. – Jim Jun 04 '18 at 13:05