Saving a view as an image.

October 16, 2009 by Skylar · 6 Comments
Filed under: Quick Tip, iPhone Development 

Another real quick tip for you. Depending on what you’re doing, why might want to capture a view and store it as an image. The frameworks make this quick and painless.

The first step you should take is to create a new image context in which we will be working. The next step is to render the view’s CALayer into that new context. Finally, we get an image from that context and close out the context.

In the following code, I use the UIWindow (UIView subclass) for the sample as a way to get a quick and easy screenshot.

Read more

Alternate UISwitch Colors

October 14, 2009 by Skylar · 3 Comments
Filed under: Quick Tip, iPhone Development 

Once again, Apple has another quite nice method in their bag of UIKit tricks that they don’t want developers using for some reason. The alternate colored UISwitch. This is often used to catch the user’s attention and make them take note. Look at the “Airplane Mode” switch, for an example. Or, the following screenshot:

Read more

Embedding UITables into UIAlertViews

October 10, 2009 by Skylar · 2 Comments
Filed under: iPhone Development 

The newer Apple firmware will create a table in your UIAlertView automatically if you create a more than the number of buttons that fit onto the alert. Note that this number is different in landscape and portrait modes. I found the implementation to be very unappealing for a few reasons. First of all, you won’t really know if you will have buttons or a table until after you compile and test the application. Plus, if you want to display a table, but you only have a few options, then there’s no real way to get that with the standard UIAlertView. And finally, what if you had wanted to customize the table with colored cells, custom cells with images on them, or take advantage of the editing properties of the table and its “Swipe to delete” feature? What if you want a table with multiple sections? You would be able to do none of the above with the standard UIAlertView.

So instead, I decided the best option would be to create another custom UIAlertView whose sole purpose is to display a table.

Read more