I have a UIView named parent. Inside parent are nested two UIViews named Child1 and Child2.(see image)
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 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
If you start with a regular UIView it has square corners. You can give it round corners by changing the cornerRadius property of the view's layer . and smaller values give less rounded corners. Both clipsToBounds and masksToBounds are equivalent.
There is no direct way to set corner radius for your button in xcode attribute inspector. So what you should do is, create a user defined run time attribute for corner radius. Key Path : layer. cornerRadius Type : Number Value : 8 //or whatever value you want for your corner radius.
I think you need to add clipToBound
on parentView
parentView.clipsToBounds = true
If you need cornerRadius
import QuartzCore
parentView.layer.cornerRadius = yourvalue
if you don't want to shadow then add
parentView.layer.masksToBounds = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With