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
- Reviews • 41
- Type Smartphone
- Operating system iOS (8)
- Screen size 4.7 inches
- Internal memory 16 GB
- Camera 8 megapixels
- Dimensions 5.44 x 2.64 x 0.27 in
- Weight 4.55 oz
- Released 2014-09-19