Skip to content

Instantly share code, notes, and snippets.

@jblocksom
Created April 2, 2014 20:57
Show Gist options
  • Save jblocksom/9943037 to your computer and use it in GitHub Desktop.
Save jblocksom/9943037 to your computer and use it in GitHub Desktop.
-(void)initOffscreenContext
{
CGSize layerSize = [self bounds].size;
layerSize.height = floorf(layerSize.height);
layerSize.width = floorf(layerSize.width);
if (layerSize.height <= 0 || layerSize.width <=0)
{
self.offscreenContext = nil;
return;
}
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = (CGContextRef) [(id) CGBitmapContextCreate(NULL, layerSize.width, layerSize.height, 8, layerSize.width*4, colorSpace, kCGImageAlphaPremultipliedLast) autorelease];
CGColorSpaceRelease(colorSpace);
CGContextTranslateCTM(ctx, 0, layerSize.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGFloat tx = layerSize.width * (1.0 - scale) * 0.5;
CGFloat ty = layerSize.height * (1.0 - scale) * 0.5;
CGRect tempbounds = CGRectZero;
tempbounds.size = layerSize;
tempbounds = CGRectIntegral(CGRectInset(tempbounds, tx, ty));
CGContextSetShadow(ctx, CGSizeMake(5,5), 5);
CGContextSetFillColorWithColor(ctx, [[UIColor whiteColor] colorWithAlphaComponent:0.5].CGColor);
CGContextFillRect(ctx, tempbounds);
self.offscreenContext = (id) ctx;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment