Created
April 23, 2014 01:07
-
-
Save watr/11199697 to your computer and use it in GitHub Desktop.
Convenient category to create UIImage from UIBezierPath
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
#import <UIKit/UIKit.h> | |
@interface UIImage (BezierPath) | |
+ (UIImage *)imageWithBezierPathFill:(UIBezierPath *)bezierPath; | |
+ (UIImage *)imageWithBezierPathStroke:(UIBezierPath *)bezierPath; | |
@end |
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
#import "UIImage+BezierPath.h" | |
@implementation UIImage (BezierPath) | |
+ (UIImage *)imageWithBezierPathFill:(UIBezierPath *)bezierPath | |
{ | |
return [self imageWithBezierPath:bezierPath | |
fill:YES | |
stroke:NO | |
scale:[[UIScreen mainScreen] scale]]; | |
} | |
+ (UIImage *)imageWithBezierPathStroke:(UIBezierPath *)bezierPath | |
{ | |
return [self imageWithBezierPath:bezierPath | |
fill:NO | |
stroke:YES | |
scale:[[UIScreen mainScreen] scale]]; | |
} | |
+ (UIImage *)imageWithBezierPath:(UIBezierPath *)bezierPath | |
fill:(BOOL)fill | |
stroke:(BOOL)stroke | |
scale:(CGFloat)scale | |
{ | |
UIImage *image = nil; | |
if (bezierPath) { | |
UIGraphicsBeginImageContextWithOptions(bezierPath.bounds.size, NO, scale); | |
if (fill) { | |
[bezierPath fill]; | |
} | |
if (stroke) { | |
[bezierPath stroke]; | |
} | |
image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
} | |
return image; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment