Skip to content

Instantly share code, notes, and snippets.

@youngshook
Last active August 29, 2015 14:01
Show Gist options
  • Save youngshook/14952f3ed2e133466f66 to your computer and use it in GitHub Desktop.
Save youngshook/14952f3ed2e133466f66 to your computer and use it in GitHub Desktop.
Painting UIBarButton Image
- (UIImage *)backButtonImage
{
static UIImage *image;
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
CGSize size = CGSizeMake(50.0, 44.0);
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
[[UIColor whiteColor] setStroke];
[[UIColor whiteColor] setFill];
UIBezierPath *path = [UIBezierPath bezierPath];
path.lineWidth = 1.5;
path.lineCapStyle = kCGLineCapButt;
path.lineJoinStyle = kCGLineJoinMiter;
[path moveToPoint:CGPointMake(11.0, 11.0)];
[path addLineToPoint:CGPointMake(1.0, 21.0)];
[path addLineToPoint:CGPointMake(11.0, 31.0)];
[path stroke];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
});
return image;
}
- (UIImage *)forwardButtonImage
{
static UIImage *image;
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
UIImage *backButtonImage = [self backButtonImage];
CGSize size = backButtonImage.size;
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat x_mid = size.width / 2.0;
CGFloat y_mid = size.height / 2.0;
CGContextTranslateCTM(context, x_mid, y_mid);
CGContextRotateCTM(context, M_PI);
[backButtonImage drawAtPoint:CGPointMake(-x_mid, -y_mid)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
});
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment