我有一个名为parent的UIView。在parent中嵌套了两个名为Child1和Child2的UIView。(参见图片)
注意:Child1、Child2和Parent之间没有边距,即边距为0。
我正在尝试将Parent的角落变圆。
parentView.layer.cornerRadius = 10
这不会使子元素的角落变圆。(见图片)
这里,上方角没有 被圆角化。因为Child2是透明的,而Child1带颜色,Parent为白色。
我尝试了以下方法:
parentView.layer.cornerRadius = 10
child1.clipsToBounds = true
没有运气。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
仍然没有运气
请帮帮我
masksToBounds
属性设置为 true。 - badhanganesh