Created
January 11, 2015 19:57
-
-
Save cdipaolo/cd4b396fa748de4a1812 to your computer and use it in GitHub Desktop.
|| Swift || Create a UIBezierPath shaped like an arrow with given dimensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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