Skip to content

Instantly share code, notes, and snippets.

@cdipaolo
Created January 11, 2015 19:57
Show Gist options
  • Save cdipaolo/cd4b396fa748de4a1812 to your computer and use it in GitHub Desktop.
Save cdipaolo/cd4b396fa748de4a1812 to your computer and use it in GitHub Desktop.
|| Swift || Create a UIBezierPath shaped like an arrow with given dimensions
extension UIBezierPath {
// creates an arrow shaped path with middle of base as start point and pointed end as end point
class func arrowPath(tailLength: CGFloat, tailWidth: CGFloat, headWidth: CGFloat) -> UIBezierPath {
let midY: CGFloat = tailWidth / 2
var polygonPath = UIBezierPath()
polygonPath.moveToPoint(CGPointMake(0, 0))
polygonPath.addLineToPoint(CGPointMake( 0, -midY))
polygonPath.addLineToPoint(CGPointMake( tailLength, -midY))
polygonPath.addLineToPoint(CGPointMake( tailLength, -headWidth))
polygonPath.addLineToPoint(CGPointMake( tailLength + headWidth, 0))
polygonPath.addLineToPoint(CGPointMake( tailLength, headWidth))
polygonPath.addLineToPoint(CGPointMake( tailLength, midY))
polygonPath.addLineToPoint(CGPointMake( 0, midY))
polygonPath.closePath()
return polygonPath
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment