iOS UIButton how does one make beautiful buttons like this? - iphone

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?

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

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

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.

And under iOS 5, you have UIAppearance.

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/

Related

How to change pull to refresh icon of tableview in swift? [duplicate]

I have been looking around but couldn't find anything good about this.
I would like to customize the default UIRefeshControl with different loader, etc. So far I can only change tintColor & attributedTitle properties and most code I found are just basically creating a new "pulltorefresh" effect but what I want is to just use the UIRefreshControl and customize it a bit.
Is this possible?
You can't add different loader without accessing private APIs, but you can add background image:
UIImageView *rcImageView =
[[UIImageView alloc] initWithImage:
[UIImage imageNamed: #"refreshControl.png"]];
[self.refreshControl insertSubview:rcImageView atIndex:0];
assuming self is an instance of UITableViewController subclass.
Image size you need is 320x43px (#2x 640x86px), the middle area (approximately 35px) will be covered by the loader animation.
I show application logo there...

iOS Background Image doesn't display properly?

I've literally piled through hundreds go searches on google :(. I can't seem to figure out what I'm doing wrong when I create an image in photoshop (960 x 600, -40 for the status bar). The image comes out to this:
When it should look like this:
(note this is not the actually size, crappy thumbnail version :P. The size is as stated above)
This is my code:
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"MenuBkground.png"]];
Am I doing something wrong when I make the image? Is it in the code? Any ideas?
You're using colorWithPatternImage which basically means what it says. The image will repeat itself if the space is not entirely consumed by the image. If you want to have a true background image you should create the image as a subview.
UIImage* image = [UIImage imageNamed:#"MenuBKground.png"];
UIImageView* background = [[UIImageView alloc]initWithImage: image];
[self.view addSubview: background];
Another way if your using interface builder,
Drag an image view to your viewController.
Assign that as MenuBkground.png in the inspector (first drop down box)

How to change the backgroundimage of a button programmaticaly when touching?

I have an IPhone application in which I am using an IBOutlet button with a background. On its click, I call a webservice and on the success of that, I need to change the background of the button. Now I am doing it in this way but nothing's happening:
UIImage *buttonImage = [UIImage imageNamed:#"follow_shop.png"];
[following setBackgroundImage:buttonImage forState:UIControlStateNormal];
Does anybody know how to achieve this?
What you have done in code is correct. You can do three things now (in decreasing order of probability of finding the issue):
1) Check in your IB if initially, you have set its image or backgroundImage. The two are different and image comes above the backgroundImage(effectively rendering backgroundImage as being hidden). Both of these (the image you set in IB and in code) should be either one (image or backgroundImage).
2) Check if follow_shop.png is the correct name. You can also use breakpoints to see if buttonImage has memory or not.
3) Check if following is connected in your IB.
Have an IBOutlet for the button and in your IBAction put this code
UIImage *buttonImage = [UIImage imageNamed:#"yourimage.png"];
[myButton setBackgroundImage:buttonImage forState:UIControlStateSelected];
Look if your IBOutlet is connected properly (e.g. using NSLog(#"%#",following);)
Re-Add your image (e.g. using Copy files into destination groups folder)
Have a look at your target. Is your image in Copy Bundle Resources?

Custom UIButton iphone

I want to change the color of my UIButton. I did this:
UIButton *alreadySubscriber = [[UIButton alloc] initWithFrame:CGRectMake(12, maxy-65, 262.0, 50)];
alreadySubscriber.layer.cornerRadius = 10.0f;
[alreadySubscriber setBackgroundColor:[UIColor orangeColor]];
[alreadySubscriber setTitle:#"Already a subscriber" forState:UIControlStateNormal];
The color of the button changes, but no longer see the effect of bright light booby top. how can I fix this?
We're unable to programmatically set this 'bubble effect' for the UIButton I'm afraid. The only way to go about it far as I can tell is to go for a custom button with an image (or two images for the normal and active states).
The resource Eugene put up earlier seems pretty good in fact.
I don't really know what kind of booby light are you talking about, but have you tried using images for your buttons? I'd suggest using two different images like those you can create here http://dabuttonfactory.com/.
You should create as a custom button and add the image/color as background.

How do I texture controls on iPhone Apps?

I would like to apply a texture to my iPhone app similar to the tab bar in GameCenter.app. Is there a good tutorial somewhere that explains this? I am hoping for a method that will translate easily to other controls as well. Thanks!
A simple way to add texture for backgrounds is to use the built in colorWithPatternImage.
UIImage *image = [UIImage imageNamed:#"backgroundPattern"];
[self setBackgroundColor:[UIColor colorWithPatternImage:image]];
If you have a toolbar you should be able to use your "Patternized UIView" with UIBarButtonItem, one of its initializers take a UIView.