i want to change the button color when it is clicked. I used :
[button setBackgroundColor:[UIColor redColor]];
but this shows red color onl
To get a button with a single color you can set the button to custom button. Here is my known list of available button api (you can set them in viewDidLoad after setting them as outlets). Just import quartz and change the border radius to make it look like a button.
//highlightcolor - this changes the status for UIControlStateHighlighted
OUTLETNAME.tintColor = [UIColor orangeColor];
//borderradius *quartz
[[OUTLETNAME layer] setCornerRadius:20.0f];
//border *quartz
[[OUTLETNAME layer] setBorderWidth:5.0f];
//bordercolor
[OUTLETNAME.layer setBorderColor:[[UIColor greenColor] CGColor]];
//backgroundcolor
OUTLETNAME.backgroundColor = [UIColor blackColor];
//image
[OUTLETNAME setImage:[UIImage imageNamed:PICNAME] forState:UIControlStateNormal];
//text
[OUTLETNAME setTitle:@"TEXT" forState:UIControlStateNormal];
//fontsize
OUTLETNAME.titleLabel.font = [UIFont systemFontOfSize:36.0];
//fontcolor
OUTLETNAME.titleLabel.textColor = [UIColor blackColor];
//fontcolor
[OUTLETNAME setTitleColor:[UIColor orangeColor] forState: UIControlStateNormal];
If you want custom buttons with a gradient color you have to make a custom button class.
This blog has a glossy button class project for download. http://didikot.com/?p=217
You have to refractor and convert to ARC to use it, I think.
This blog does the same thing but without the gloss. http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
You have everything correct. Just set your button type to UIButtonTypeCustom..
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(200, 8, 100, 30);
[button setTitle:@"Set up" forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor greenColor]];
button.clipsToBounds = YES;
button.layer.cornerRadius = 10;
button.alpha = 0.5;