Created
April 2, 2014 20:57
-
-
Save jblocksom/9943037 to your computer and use it in GitHub Desktop.
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
-(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