2

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?

M. Kremer
  • 679
  • 6
  • 24
mding5692
  • 806
  • 1
  • 10
  • 34

1 Answers1

-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