Skip to content

Instantly share code, notes, and snippets.

@elfenlaid
Created May 30, 2014 15:42
Show Gist options
  • Save elfenlaid/25ac54784cd349ca455a to your computer and use it in GitHub Desktop.
Save elfenlaid/25ac54784cd349ca455a to your computer and use it in GitHub Desktop.
Simple copypaste became the reason of interesting debug story :)
+ (UIImage *)generatedBackground {
static NSArray *colors = nil;
if (!colors) {
colors = @[
[UIColor colorWithRed:0.957 green:0.138 blue:0.287 alpha:1.000],
...
[UIColor colorWithRed:0.972 green:0.207 blue:0.225 alpha:1.000],
];
}
UIImage *overlay = [UIImage imageNamed:@"backgroundRoundOverlay"];
UIImage *heavyOverlay = [UIImage imageNamed:@"heavyBackgroundOverlay"];
UIImage *image = nil;
UIGraphicsBeginImageContextWithOptions(overlay.size, YES, .0);
{
[colors[arc4random() % colors.count] setFill];
[[UIBezierPath bezierPathWithRect:(CGRect) {CGPointZero, overlay.size}] fill];
[overlay drawAtPoint:CGPointZero];
[heavyOverlay drawAtPoint:CGPointZero blendMode:kCGBlendModeNormal alpha:.3];
image = UIGraphicsGetImageFromCurrentImageContext();
}
UIGraphicsGetImageFromCurrentImageContext(); // <<- ooops, UIGraphicsEndImageContext intendent call
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment