Im using an UIView as an overlay with a drop shadow, however once I set the UIView background color to .clear, I no longer see the shadow, is there a way to add shadows to an UIView with clear background color?
Asked
Active
Viewed 2,172 times
2
-
Transparent objects don't cast shadows. Try using an image instead – Leo Dabus Oct 22 '17 at 04:11
-
That makes sense, I figured out another way to do the overlay which doesnt use transparent UIViews – mding5692 Oct 22 '17 at 04:20
-
@mding5692 did you managed to find a solution to this? If so then post your solution so others can use it in the future – sam_smith Mar 21 '18 at 03:14
-
1Please find my answer to this question here: https://stackoverflow.com/a/56194429/8903877 – Ross Krasner May 17 '19 at 22:53
-
the correct way to add shadows with a hole in the middle: https://stackoverflow.com/a/59092828/294884 – Fattie Nov 25 '22 at 14:11
1 Answers
-3
Yes It is work by giving opacity layer less than 10
@IBInspectable var shadowOffsetX : CGFloat = 0
@IBInspectable var shadowOffsetY : CGFloat = 0
@IBInspectable var shadowColor : UIColor? {
didSet{
self.layer.shadowColor = shadowColor?.cgColor
}
}
@IBInspectable var shadowOpacity : Float = 0 {
didSet{
self.layer.shadowOpacity = shadowOpacity
}
}
@IBInspectable var shadowRadius : CGFloat = 0 {
didSet{
self.layer.shadowRadius = shadowRadius
}
}
@IBInspectable var cornerRadius : CGFloat = 0 {
didSet{
layer.cornerRadius = cornerRadius
layer.masksToBounds = true
}
}
@IBInspectable var borderWidth : CGFloat = 0 {
didSet{
layer.borderWidth = borderWidth
}
}
@IBInspectable var borderColor : UIColor? {
didSet{
layer.borderColor = borderColor?.cgColor
}
}
@IBInspectable var layerOpacity : Float = 0 {
didSet{
self.layer.opacity = layerOpacity
}
}
override func awakeFromNib() {
super.awakeFromNib()
self.layer.shadowOffset = CGSize(width: shadowOffsetX, height: shadowOffsetY)
}

Sairam
- 17
- 2