View Images And PDF Files In Realtime With Mac OS X Preview While Debugging iOS Apps

David Dengg recently contacted me with a unique tip that can be quite helpful if you are creating or manipulating UIImage objects and/or PDF files in your iOS app.

The basic idea is to show objects in realtime in the Preview app on your Mac development machine while your application is running in the simulator. Let me show you how this works – in the code below (from yesterday’s post on cropping an image), I create a UIImage object that is cropped from another image:

UIImage *image = [UIImage imageNamed:@"mountains.png"];
// Create rectangle from middle of current image
CGRect croprect = CGRectMake(image.size.width / 4, image.size.height / 4 ,
  (image.size.width / 2), (image.size.height / 2));
// Draw new image in current graphics context
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], croprect);
// Create new cropped UIImage
UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];

Continue reading