Reputation: 1291
Is this a UIButton? If it is, how is the background red done? Obviously, it is not red UIColor? Is there same tool or utility included with Xcode to allow making buttons like this?
Upvotes: 19
Views: 12232
Reputation: 8772
You can make a button like that with core animation layers.
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
Upvotes: 4
Reputation: 15788
I wrote a couple of classes to generate buttons for a calculator I wrote. The classes generate the buttons based upon either standard colors or with RGB input RGB values. The buttons are in my BindleKit project on Github: https://github.com/bindle/BindleKit
My answer to Change UIButton background color describes how to use the classes and where to find the source.
To see examples of the buttons, compile the BKCatalog app in the Github project or look at the screenshot https://github.com/bindle/BindleKit/blob/master/screenshots/BKCatalog-BKButtons.png
Upvotes: 5
Reputation: 112857
You need to create a background image for the button.
Then add the image to the button:
- (void)setImage:(UIImage *)image forState:(UIControlState)state
Also for resizable buttons see:
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets
You can use programs like Graphics Converter, Photoshop and others.
Upvotes: 4
Reputation: 19641
You can generate similar buttons with private class UIGlassButton
.
I saw it first here http://pastie.org/830884 by @schwa.
Run an app with this code in your iOS simulator to create a custom button (or in the device, save to $(APP)/Documents and enable iTunes file sharing).
Class theClass = NSClassFromString(@"UIGlassButton");
UIButton *theButton = [[[theClass alloc] initWithFrame:CGRectMake(10, 10, 120, 44)] autorelease];
// Customize the color
[theButton setValue:[UIColor colorWithHue:0.267 saturation:1.000 brightness:0.667 alpha:1.000] forKey:@"tintColor"];
//[theButton setTitle:@"Accept" forState:UIControlStateNormal];
[self.view addSubview:theButton];
UIGraphicsBeginImageContext(theButton.frame.size);
CGContextRef theContext = UIGraphicsGetCurrentContext();
[theButton.layer renderInContext:theContext];
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
NSData *theData = UIImagePNGRepresentation(theImage);
[theData writeToFile:@"/Users/<# your user #>/Desktop/button.png" atomically:NO];
UIGraphicsEndImageContext();
Once you obtain the png, use it as button background.
Alternatively, you can build the buttons programmatically (by Jeff Lamarche).
Upvotes: 15