2
我有一個CAShapeLayer
只有底部圓角。我想要的是在底部添加陰影,但它不起作用,即使代碼看起來顯然是正確的。它所有的東西都圍繞着底角,但我沒有看到陰影。用CAShapeLayer添加陰影?
let shapeLayer = CAShapeLayer()
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: 20, height: 20)).cgPath
shapeLayer.path = path
shapeLayer.shadowColor = UIColor(r: 233, g: 233, b: 233).cgColor
shapeLayer.shadowOffset = CGSize(width: 0.0, height: 2.8)
shapeLayer.shadowOpacity = 1.0
shapeLayer.shadowRadius = 0.0
shapeLayer.shouldRasterize = true
shapeLayer.rasterizationScale = UIScreen.main.scale
layer.rasterizationScale = UIScreen.main.scale
layer.mask = shapeLayer
感謝!我從這個問題得到了一個想法。我所做的只是創建一個帶陰影的虛擬背景視圖;並將其插入到具有圓角的視圖中(使用'insertSubView')。 –
將子圖層添加到我的圖層會使視圖完全變黑 –