Skip to content

Instantly share code, notes, and snippets.

@peyton
Created March 6, 2012 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peyton/1988678 to your computer and use it in GitHub Desktop.
Save peyton/1988678 to your computer and use it in GitHub Desktop.
Block-based helpers for CGContexts
/**
* CGContextBlocks.h
*
* Block-based convenience methods for organizing Core Graphics-heavy code.
*
* See https://gist.github.com/gists/1988678 for the latest version.
*
* Idea stolen from http://www.natestedman.com/post/improving-cgcontext-with-blocks/
*/
typedef void(^CGStateBlock)();
void CGContextState(CGContextRef ctx, CGStateBlock actions)
{
CGContextSaveGState(ctx);
actions();
CGContextRestoreGState(ctx);
}
void CGContextTransparencyLayer(CGContextRef ctx, CGStateBlock actions)
{
CGContextBeginTransparencyLayer(ctx, NULL);
actions();
CGContextEndTransparencyLayer(ctx);
}
// End CGContextBlocks.h //
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment