Sometimes the default look of iOS controls (such as
UIButton) is a little 'flat'. Apple themselves sometimes use a very pretty 'glass button' effect, which could be achieved (apparently, I'm paraphrasing here) using an undocumented
UIGlassButton class. You can read more about this in the source links for this sample:
- MonoTouch tips and snippets, which points to...
- Martin Bowling's MTGlassButton (ZIP file), which seems related to...
- Erica Sudan's Shiny buttons devsugar, which uses...
- @schwa (Jonathan Wight)'s Objective-C version
GlassButton.dllwrapper as part of a sample project that allows you to create great-looking PNG-image-glass-buttons to incorporate into your iOS projects. The only thing missing was a double-resolution version for my new iPhone4's Retina Display, so that's what I've added to this github project: GlassButtonGenerator.
How it works:
- Edit the string constants for button text and filename
- Edit the filename which is used in the path to save the output
- Run the app in the Simulator and press the [Generate Glass Button] button
- Grab the images that are saved to your Desktop
- Use the images in your iOS app in
If you are then wondering what to do with the two images, check out Miguel's post on Building apps for the Retina Display. Basically you should use
UIImage.FromBundleto load the image and ensure that the 'regular' and 'retina' versions have the same filename (with the 'retina' version having a suffix @2x).
For the code below, the
/Images/folder has four images: BuyGlass.png, BuyGlass@2x.png, CancelGlass.png, CancelGlass@2x.png (where the @2x images have double the height & width dimensions of the base image)...
buyButton.SetImage( UIImage.FromBundle("Images/BuyGlass.png") , UIControlState.Normal); cancelButton.SetImage( UIImage.FromBundle("Images/CancelGlass.png") , UIControlState.Normal);
Don't forget to make the Build Action: Content for your image files! And remember, DON'T use
UIGlassButtonin your apps directly - generate the images and include them.
UPDATE (May 2011): Miguel has posted a code-based glass button implementation which you might prefer to this pre-generated image one. See Glass button for iPhone and the code on github.