title: iOS Swift: How to merge two shapes into a solid color shape using UIBezierPath?
body: <p><a href="https://i.stack.imgur.com/egBGS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/egBGS.png" alt="enter image description here"></a></p>
  
  <p>Hey~~
  I am trying to draw a solid round dot with a rectangle handle on top of it.
  (backcolor: purple, forecolor: black)</p>
  
  <p>However, the shapes are all correct, but when I am coloring it, there is a gap at the shape overlapping area, which cannot be filled with solid color.</p>
  
  <p>How should I correct it? Thanks!</p>
  
  <pre><code>var shapeLayer: CAShapeLayer!
  
  func draw() {
      let path = UIBezierPath()
  
      // draw a rectangle
      path.move(to: CGPoint(x: 90, y: 0))
      path.addLine(to: CGPoint(x: 90, y: 100))
      path.addLine(to: CGPoint(x: 110, y: 100))
      path.addLine(to: CGPoint(x: 110, y: 0))
      path.addLine(to: CGPoint(x: 90, y: 0))
  
      // draw a circle
      path.move(to: CGPoint(x: 100, y: 100))
      path.addArc(withCenter: CGPoint(x: 100, y: 100), radius: 50, startAngle: 0, endAngle: 2 * CGFloat.pi, clockwise: true)
  
      // fill colors with purple and black
      self.shapeLayer.path = path.cgPath
      self.shapeLayer?.fillColor = foreColor.cgColor
      self.backgroundColor = backColor
  }
  </code></pre>