I have a UIView named parent . Inside parent are nested two UIViews named Child1 and Child2 .(see image)
Note: There are no margins ie 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
我认为你需要在clipToBound
上添加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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.