It's a great little trick, and one worth adding to your development arsenal. Be aware that UIGlassButton is a private class, and one that has long since been relegated away from the official SDK development path. Although it continues to work on the Simulator, it's not for use on the iPhone itself or in App Store projects.
Continue reading on to find the code. Don't forget to substitute your own user folder into the code (in my case, "ericasadun") for Jonathan's ("schwa").
// Code to create a "Glass" button and render it to a png on your desktop.
// Run this from the SIMULATOR and change my username to yours.
// Update: This uses a private iPhone SDK. Do not use this code in your shipping app.
// Use it merely to generate the PNG file for you to use in a fake button.
Class theClass = NSClassFromString(@"UIGlassButton");
UIButton *theButton = [[[theClass alloc] initWithFrame:
CGRectMake(10, 10, 120, 44)] autorelease];
[theButton setValue:[UIColor colorWithHue:0.267
saturation:1.000 brightness:0.667 alpha:1.000]
CGContextRef theContext = UIGraphicsGetCurrentContext();
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
NSData *theData = UIImagePNGRepresentation(theImage);
[theData writeToFile:@"/Users/schwa/Desktop/test.png" atomically:NO];
- Key specs
- Type Smartphone
- Operating system iOS
- Screen size 4.7 inches
- Internal memory 16 GB
- Carriers (US) AT&T
- Dimensions 5.44 x 2.64 x 0.28 in
- Weight 5.04 oz
- Released 2015-09-25