Created
June 14, 2014 16:48
-
-
Save loganwright/e11e5990ff99a0c761fa to your computer and use it in GitHub Desktop.
Squiggle UIBezierPath
This file contains hidden or 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
- (void) drawSquiggleInRect:(CGRect)rect { | |
// Assure positive values | |
rect = CGRectStandardize(rect); | |
// Find anchor points | |
CGPoint anchorLowerLeft = CGPointMake(rect.origin.x, rect.origin.y + rect.size.height); | |
CGPoint anchorTopRight = CGPointMake(rect.origin.x + rect.size.width, rect.origin.y); | |
// 10.0 works pretty good! | |
// 10% of the width | |
CGFloat offset = rect.size.width * 0.1;//10.0; | |
// Left control offset_X: -10 -- offset_Y -(height * 2.0) | |
CGPoint topControlPointOne = CGPointMake(anchorLowerLeft.x - offset, anchorLowerLeft.y - (rect.size.height * 2.0) - (offset / 2.0)); | |
CGPoint topControlPointTwo = CGPointMake(anchorTopRight.x - offset, anchorLowerLeft.y + offset); | |
CGPoint lowerControlPointOne = CGPointMake(anchorTopRight.x + offset, anchorTopRight.y + (rect.size.height * 2.0) + (offset / 2.0)); | |
CGPoint lowerControlPointTwo = CGPointMake(anchorLowerLeft.x + offset, anchorTopRight.y - offset); | |
UIBezierPath * path = [UIBezierPath new]; | |
[path addClip]; | |
path.lineJoinStyle = kCGLineJoinRound; | |
path.lineWidth = 2.0; | |
[path moveToPoint:anchorLowerLeft]; | |
[path addCurveToPoint:anchorTopRight controlPoint1:topControlPointOne controlPoint2:topControlPointTwo]; | |
[path addCurveToPoint:anchorLowerLeft controlPoint1:lowerControlPointOne controlPoint2:lowerControlPointTwo]; | |
[path closePath]; | |
[path stroke]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment