Swift 3: 嵌套的 UIView(s) 角没有变圆
Swift 3: nested UIView(s) corners not getting rounded
我有一个名为 parent 的 UIView。 parent 内嵌套了两个 UIView,分别命名为 Child1 和 Child2。(见图)
注意:没有边距,即 Child1、Child2 和 Parent 都为 0 b/w。
我正在尝试 绕过 Parent。
parentView.layer.cornerRadius = 10
这 不圆 children 的角。(见图)
顶角不最终得到圆。底角是圆角的,因为 Child2 是 transparent 而 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
仍然没有运气
请帮帮我
我认为您需要在 parentView
上添加 clipToBound
parentView.clipsToBounds = true
如果需要cornerRadius
import QuartzCore
parentView.layer.cornerRadius = yourvalue
如果你不想影子然后添加
parentView.layer.masksToBounds = true
我有一个名为 parent 的 UIView。 parent 内嵌套了两个 UIView,分别命名为 Child1 和 Child2。(见图)
注意:没有边距,即 Child1、Child2 和 Parent 都为 0 b/w。
我正在尝试 绕过 Parent。
parentView.layer.cornerRadius = 10
这 不圆 children 的角。(见图)
顶角不最终得到圆。底角是圆角的,因为 Child2 是 transparent 而 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
仍然没有运气
请帮帮我
我认为您需要在 parentView
clipToBound
parentView.clipsToBounds = true
如果需要cornerRadius
import QuartzCore
parentView.layer.cornerRadius = yourvalue
如果你不想影子然后添加
parentView.layer.masksToBounds = true