title: How To Add Border To a UIView With Mask?
body: <p>Here's what I need to do to my two buttons.</p>
  
  <p><a href="https://i.stack.imgur.com/tByQ2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tByQ2.png" alt="enter image description here"></a></p>
  
  <p>and here's what I got right now.</p>
  
  <p><a href="https://i.stack.imgur.com/B3yUu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B3yUu.png" alt="enter image description here"></a></p>
  
  <p>What I'm doing:
  - Set these up in IB inside a stackView.
  - Add masks
  - Add borders with width and color
  - Add shadow.</p>
  
  <p>The borders are being added but being cut-off as well by the masks.</p>
  
  <p>Codes:</p>
  
  <pre><code>public func addCornerRadiusToCorners(
      _ corners: UIRectCorner,
      cornerRadius: CGFloat,
      borderColor: UIColor,
      borderWidth: CGFloat) {
  
      //        self.layer.masksToBounds = true
      //        self.clipsToBounds = true
      self.layer.borderWidth = borderWidth
      self.layer.borderColor = borderColor.cgColor
  
      let size = CGSize(width: cornerRadius, height: cornerRadius)
      let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: size)
      let mask = CAShapeLayer()
      mask.path = path.cgPath
      self.layer.mask = mask
  
  }
  
  public func addDefaultShadow() {
      let shadowPath = UIBezierPath(rect: self.bounds)
  
      self.layer.masksToBounds = false
      self.layer.shadowOffset = CGSize(width: 1, height: 1)
      self.layer.shadowOpacity = 0.5
      self.layer.shadowPath = shadowPath.cgPath
  }
  </code></pre>
  
  <p>Any idea how to achieve the result in the first photo?</p>
  
  <p>EDIT: the border is being cut, the result was just got from the UI Debugger of Xcode. Sorry.</p>