views:

8421

answers:

7

Using the iPhone SDK, how would I go about creating a red "delete" button similar to the one used when deleting contacts on the iPhone?

Screenshot (I'm trying to duplicate the red button at the bottom)

Thanks!

A: 

You can create a separate section in your grouped table view, give that section only one row, and set that cell's background image to a red gradient image. You'll have to recreate that image on your own, though.

Tim
while this works, it is not a customizable as my presented solution as in order to get special highlighting or states, you would need to implement custom logic that Apple already includes in the UIButton class
coneybeare
A: 

This question is very close to yours, and contains a couple of ways of generating such a colored button.

Brad Larson
+25  A: 
coneybeare
Thanks, it worked!
igul222
Nice, elegant solution. +1
Tim
Good solution. Just one codefix: you forgot the @-sign for the string in -[UIImage imageNamed:].
Jonathan Sterling
Anyone have a green one?
Anthony Glyadchenko
Note: Anthony's Question was answered here: http://stackoverflow.com/questions/2276099/a-big-green-uiimage-anyone/2276272
amphetamachine
Excellent post - thanks for the free image, I'll be using it :)
Steve Neal
Thank you for the image! It was exactly what I was searching for!
IcyBlueRose
+1  A: 

Probably the simplest way to do it is to snag this iPhone GUI Photoshop file that contains lots of UI elements in PSD layers, then change the tint of the large button in Photoshop and save it as a PNG.

One advantage of doing it this way is that you can also create versions for button selected and/or highlight state and assign the images to a standard UIButton.

Ramin
one disadvantage is you need to keep tons of large images in your bundle, and they will not fit the screen on a different rotation
coneybeare
+2  A: 

I've done this recently also, and creating this button for it (and some Monotouch example code for any monotouchers):

alt text

It has less of a bevel which works better on any background, but doesn't match the iPhone UIGlassButton exactly.

Chris S
+3  A: 

I think those ones are better (and they look fine on retina display too) :

alt text alt text

.png generated from this very nice .psd file : http://www.teehanlax.com/blog/2010/08/12/iphone-4-gui-psd-retina-display/

And then use it as a strechable image for the background of your UIButton:

UIImage* greenButton = [UIImage imageNamed:@"UIButton_green.png"]; 
UIImage *newImage = [greenButton stretchableImageWithLeftCapWidth:greenButton.size.width/2 topCapHeight:greenButton.size.height/2];
[callButton setBackgroundImage:newImage forState:UIControlStateNormal];

yonel