title: Triangle UIView - Swift
body: <p>So I'm making a game in which I am dropping objects which have to be destroyed by a spike(triangle) at the bottom of the screen by a user.</p>
  
  <p>I cannot work out how to make a UIView that is a triangle. However I have been able to make it work as a rectangle like this:</p>
  
  <pre><code> let barrier = UIView(frame: CGRect(x:125, y: 650, width: 130, height:20))
   barrier.backgroundColor = UIColor.orangeColor()
   view.addSubview(barrier)
  </code></pre>
  
  <p>And this has worked. But I cannot work out how to make a triangle. The reason I want it as a UIView is because im using collisions on it and for the user to move it. I have tried a PNG triangle but it detects the collision as the border of the image not the start of the triangle. </p>
  
  <p>I have tried this but it doesn't work...</p>
  
  <pre><code> let square = UIView(frame: CGPathMoveToPoint(path, nil, 50, 0), CGPathAddLineToPoint(path, nil, 100, 50), CGPathAddLineToPoint(path, nil, 0, 100))
   square.backgroundColor = UIColor.purpleColor()
   view.addSubview(square)
  </code></pre>
  
  <p>Any and all help will be appreciated,</p>
  
  <p>Thanks,</p>
  
  <p>Alex</p>