【问题标题】:Swift 3: nested UIView(s) corners not getting roundedSwift 3:嵌套的 UIView(s) 角没有变圆
【发布时间】:2018-01-05 10:30:42
【问题描述】:

我有一个名为 parentUIView。父级内部嵌套了两个名为 Child1Child2 的 UIView。(见图)

注意:没有边距,即 Child1、Child2 和 Parent 的边距均为 0。

我正在尝试绕过 Parent 的角落

parentView.layer.cornerRadius = 10

不圆孩子们的角落。(见图)

顶角确实不会最终在此处得到圆形。底角是圆形的,因为 Child2 是透明的,而 Child1 是彩色的。父母是白色的。

到目前为止我已经尝试过:

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

还是没有运气

请帮帮我

【问题讨论】:

  • 设置 .clipsToBounds = true。这将隐藏图层的溢出
  • cornerRadius 和 clipsToBounds = true 的子元素和父元素
  • 将父层的masksToBounds设置为true。

标签: ios uiview swift3 cornerradius


【解决方案1】:

我认为您需要在parentView 上添加clipToBound

parentView.clipsToBounds = true

【讨论】:

  • 工作就像一个魅力!
【解决方案2】:

如果你需要cornerRadius

import QuartzCore

parentView.layer.cornerRadius = yourvalue

如果你不想阴影,那么添加

parentView.layer.masksToBounds = true 

【讨论】:

    猜你喜欢
    • 2016-01-21
    • 1970-01-01
    • 2018-02-21
    • 2018-03-24
    • 1970-01-01
    • 2017-11-27
    • 2011-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多