title: CornerRadius and Shadow on a UIView using @IBInspectable Swift 4.2
body: <p>Is it possible to have both <code>CornerRaduis</code> and a shadow on a <code>UIView</code>?</p>
  
  <p>I set up a Custom class for a <code>UIView</code> which uses <code>@IBInspectable</code> to set a <code>cornerRadius</code> and a <code>addShadow</code> which can be <code>true</code> or <code>false</code>. When I set the <code>cornerRadius</code> the shadow doesn't display, if I take away the <code>cornerRadius</code> then it displays again. Thanks in advance!</p>
  
  <p>Custom class:</p>
  
  <pre><code>import UIKit
  
  class CustomUIView: UIView {
  
      override func awakeFromNib() {
          self.layer.masksToBounds = cornerRadius &gt; 0
      }
  
      @IBInspectable var useDefaultRadius: Bool = true {
          didSet {
              self.layer.masksToBounds = cornerRadius &gt; 0
          }
      }
  
      @IBInspectable var cornerRadius: CGFloat {
          set {
              self.layer.cornerRadius = newValue
  
          }
          get {
              if (useDefaultRadius) {
                      // Set default radius
                      self.layer.cornerRadius = 23
                  }
  
              return self.layer.cornerRadius
          }
      }
  
      @IBInspectable var addShadow:Bool = true{
  
          didSet(newValue) {
              if(newValue == true){
                  self.layer.masksToBounds = false
                  self.layer.shadowColor = UIColor.black.cgColor
                  self.layer.shadowOpacity = 0.5
                  self.layer.shadowOffset = CGSize(width: 2, height: 3)
                  self.layer.shadowRadius = 3
  
                  self.layer.shadowPath = UIBezierPath(rect: bounds).cgPath
                  self.layer.shouldRasterize = true
                  self.layer.rasterizationScale =  UIScreen.main.scale
                  print("trying to use shadow")
              }
          }
  
      }
  
  
  }
  </code></pre>