Skip to content

Instantly share code, notes, and snippets.

@rbaulin
Last active October 24, 2015 17:58
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 rbaulin/d491e349fd0aade48a1b to your computer and use it in GitHub Desktop.
Save rbaulin/d491e349fd0aade48a1b to your computer and use it in GitHub Desktop.
- (UIImage *)render:(CGRect)frame {
if (CGRectIsEmpty(frame) || CGRectIsInfinite(frame) || CGRectIsNull(frame)) {
return nil;
}
UIGraphicsBeginImageContextWithOptions(frame.size, NO, 0); // same as [[UIScreen mainScreen] scale]
// drawing code
// Create new image
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// newImage = [newImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// newImage = [newImage resizableImageWithCapInsets:UIEdgeInsetsMake(r, r, r, r)];
return newImage;
}
// gist static frame size variant
UIImage *<#name#>Image() {
CGRect frame = CGRectMake(0, 0, <#width#>, <#height#>);
// Create context
UIGraphicsBeginImageContextWithOptions(frame.size, NO, 0);
// Render
// Create new image
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment