Created
January 14, 2013 22:36
-
-
Save tarnfeld/4534175 to your computer and use it in GitHub Desktop.
Create a bezier path with rounded corners based on a radius and existing frame. Most useful if you want to add in other shapes into the path while still maintaining rounded corners (for example, an arrow).
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
- (UIBezierPath *)roundedPathFromRect(CGRect)f | |
{ | |
UIBezierPath *path = [[UIBezierPath alloc] init]; | |
NSInteger radius = 4.0; | |
// Draw the path | |
[path moveToPoint:CGPointMake(radius, 0)]; | |
[path addLineToPoint:CGPointMake(f.size.width - radius, 0)]; | |
[path addArcWithCenter:CGPointMake(f.size.width - radius, radius) | |
radius:radius | |
startAngle:- (M_PI / 2) | |
endAngle:0 | |
clockwise:YES]; | |
[path addLineToPoint:CGPointMake(f.size.width, f.size.height - radius)]; | |
[path addArcWithCenter:CGPointMake(f.size.width - radius, f.size.height - radius) | |
radius:radius | |
startAngle:0 | |
endAngle:- ((M_PI * 3) / 2) | |
clockwise:YES]; | |
[path addLineToPoint:CGPointMake(radius, f.size.height)]; | |
[path addArcWithCenter:CGPointMake(radius, f.size.height - radius) | |
radius:radius | |
startAngle:- ((M_PI * 3) / 2) | |
endAngle:- M_PI | |
clockwise:YES]; | |
[path addLineToPoint:CGPointMake(0, radius)]; | |
[path addArcWithCenter:CGPointMake(radius, radius) | |
radius:radius | |
startAngle:- M_PI | |
endAngle:- (M_PI / 2) | |
clockwise:YES]; | |
return path; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment