Skip to content

Instantly share code, notes, and snippets.

@JaviSoto
Created May 2, 2013 19:12
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JaviSoto/5504598 to your computer and use it in GitHub Desktop.
Save JaviSoto/5504598 to your computer and use it in GitHub Desktop.
iOS Debug display image function
/**
* @discussion takes the passed image parameter and displays a view controller modally that shwos the image
* You can call it from the debugger like this:
* expr JSDebugDisplayImage(image)
* @note you can dismiss the view controller simply by tapping on it
*/
extern void JSDebugDisplayImage(UIImage *image);
@interface JSDebugDisplayImageViewController : UIViewController
- (id)initWithImage:(UIImage *)image;
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, weak) UIImageView *imageView;
@end
@implementation JSDebugDisplayImageViewController
- (id)initWithImage:(UIImage *)image
{
if ((self = [super init]))
{
self.image = image;
}
return self;
}
- (void)loadView
{
[super loadView];
self.imageView = [[UIImageView alloc] initWithImage:self.image];
self.imageView.frame = self.view.bounds;
self.imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:self.imageView];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
void JSDebugDisplayImage(UIImage *image)
{
JSDebugDisplayImageViewController *imageVC = [[JSDebugDisplayImageViewController alloc] initWithImage:image];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:imageVC animated:YES completion:nil];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment