【发布时间】:2018-06-13 20:26:56
【问题描述】:
我正在尝试在视图顶部创建阴影。
这是我的层次结构:
视图
------TablewView
------底部视图
TableView 和 BottomView 具有相同的父级:View。
我希望 BottomView 在 TableView 顶部有一个阴影,就像左边的图片一样,但结果是右边的那个:
如果我尝试删除 TableView,我会看到阴影。 BottomView 有圆角。 这是 BottomView 类:
class BottomView: UIView {
private var shadowLayer: CAShapeLayer!
override func layoutSubviews() {
super.layoutSubviews()
if shadowLayer == nil {
let shadowLayer = CAShapeLayer()
shadowLayer.masksToBounds = false
//rect is an ex.
shadowLayer.path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: 200, height: 80), cornerRadius: 9).cgPath
shadowLayer.fillColor = UIColor.red.cgColor
shadowLayer.shadowColor = UIColor.black.cgColor
shadowLayer.shadowPath = shadowLayer.path
shadowLayer.shadowOffset = CGSize(width: 5, height: -5)
shadowLayer.shadowOpacity = 1
shadowLayer.shadowRadius = 3
shadowLayer.zPosition = 10
layer.insertSublayer(shadowLayer, at: 0)
clipsToBounds = false
}
}
}
【问题讨论】:
标签: ios swift uiview shadow cashapelayer