Skip to content

Instantly share code, notes, and snippets.

@jfahrenkrug
Created July 9, 2010 12:04
Show Gist options
  • Save jfahrenkrug/469394 to your computer and use it in GitHub Desktop.
Save jfahrenkrug/469394 to your computer and use it in GitHub Desktop.
-(void)drawInContext:(CGContextRef)myContext {
CGContextSaveGState(myContext);// 6
CGFloat potentialFlip = 1.0;
CGFloat shadowBlur = 4;
CGFloat shadowOffset = 4;
CGFloat shadowOffsetNeg = shadowOffset * -1.0;
CGFloat x = self.bounds.origin.x + shadowOffset;
CGFloat y = self.bounds.origin.y + shadowOffset;
CGFloat wd = self.bounds.size.width - (shadowOffset * 2);
CGFloat ht = self.bounds.size.height - (shadowOffset * 2);
NSString *reqSysVer = @"3.2";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
//NSLog(@"current os version: %@", currSysVer);
if ([currSysVer compare:reqSysVer options:NSNumericSearch] == NSOrderedAscending)
{
//NSLog(@"on ios < 3.2, flipping vertical offset");
// see http://github.com/facebook/three20/issues/closed?authenticity_token=81bd5d471e7545bb0ed1f361249bb734fbf5a44b#issue/158
potentialFlip = -1.0;
}
// left side and top
CGContextSetShadow (myContext, CGSizeMake (shadowOffsetNeg, shadowOffsetNeg * potentialFlip), shadowBlur); // 7
CGContextFillRect (myContext, CGRectMake (x, y, wd, ht));
// right side and top
CGContextSetShadow (myContext, CGSizeMake (shadowOffset, shadowOffsetNeg * potentialFlip), shadowBlur); // 7
CGContextFillRect (myContext, CGRectMake (x + wd - shadowOffset, y, shadowOffset, ht));
// missing top cube on the right
CGContextSetShadow (myContext, CGSizeMake (0, shadowOffsetNeg * potentialFlip), shadowBlur); // 7
CGContextFillRect (myContext, CGRectMake (x + wd - shadowOffset, y, shadowOffset, ht));
// bottom left
CGContextSetShadow (myContext, CGSizeMake (shadowOffsetNeg, shadowOffset * potentialFlip), shadowBlur); // 7
CGContextFillRect (myContext, CGRectMake (x, y + ht - shadowOffset, wd, shadowOffset));
//missing cube on the bottom left
CGContextSetShadow (myContext, CGSizeMake (shadowOffsetNeg, 0), shadowBlur); // 7
CGContextFillRect (myContext, CGRectMake (x, y + ht - shadowOffset, shadowOffset, shadowOffset));
//bottom right corner
CGContextSetShadow (myContext, CGSizeMake (shadowOffset, shadowOffset * potentialFlip), shadowBlur); // 7
CGContextFillRect (myContext, CGRectMake (x + wd - (shadowOffset * 2), y + ht - (shadowOffset * 2), shadowOffset * 2, shadowOffset * 2));
CGContextRestoreGState(myContext);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment