Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS UIButton how does one make beautiful buttons like this?

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?

enter image description here

like image 824
geekyaleks Avatar asked Oct 28 '11 15:10

geekyaleks


People also ask

What is an iOS button?

class UIButton : UIControl. The buttons are one of the most important parts of iOS applications. Buttons are associated with the actions that are performed when the user interacts with the button. We can add the button to the iOS application programmatically or by using interface builder.

What is swift button?

SwiftUI's button is similar to UIButton , except it's more flexible in terms of what content it shows and it uses a closure for its action rather than the old target/action system. To create a button with a string title you would start with code like this: Button("Button title") { print("Button tapped!") }


1 Answers

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).

like image 145
djromero Avatar answered Sep 21 '22 06:09

djromero