// elrepositorio the random musings of Jeff Forbes

20Sep/090

A Simple Code Sample

First thing's first, my company is hiring iPhone developers. If you are an experienced iPhone/Cocoa developer, please contact me. Please.

Recently, we have been getting a decent amount of resumes to apply for a position at 9mmedia. One of them was interesting in that the potential candidate sent in a test that another company was sending out to weed out people: PDF Link

23Nov/080

iPhone Dev Tip #1: Taking a Screenshot

Since this is what I do for a living, I thought I'd start posting some tips for iPhone development. Most of the time, these will be cross-posted (or asked by me) on http://www.stackoverflow.com since I participate in the Q/A there. The site is a fantastic resource -- check it out.

Without further adieu, tip #1. This is a pretty important thing to do in a lot of cases and not easily understood by looking at the documentation in the SDK. Funnily enough, it can be boiled down to a few short lines:

UIGraphicsBeginImageContext(self.view.frame.size); //size of your screenshot

//render the view you want in the new image context
[[self.view layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
[image retain]; //this is an unretained UIImage, so let's save it
UIGraphicsEndImageContext();

That's it. There's a lot more to be said about CGContexts and the like, but a lot of the difficulty of working with these are simplified with the UIGraphics*() functions. Search for them in the XCode documentation.

Tune in next time for another helpful tip! :D

Filed under: iPhone Tips No Comments