Swift 3: nested UIView(s) corners not getting rounded

Viewed 5394

I have a UIView named parent. Inside parent are nested two UIViews named Child1 and Child2.(see image) Parent-Child Relation

Note: There are no margins i.e. 0 margin b/w both Child1, Child2 and Parent.

I am trying to round the corners of Parent.

parentView.layer.cornerRadius = 10

This does not round up the corners of the children.(see image)

The top corners do not get rounded

The top corners do not end up getting round here. The bottom corners are rounded because Child2 is transparent while Child1 is colored. Parent is white in color.

What I've tried so far:

parentView.layer.cornerRadius = 10
child1.clipsToBounds = true

No luck

parentView.layer.cornerRadius = 10
let maskLayer = CAShapeLayer()
maskLayer.path = UIBezierPath(roundedRect: view.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 10, height: 10)).cgPath
child1.layer.mask = maskLayer

Still No luck

Please help me out

2 Answers
Related