4

how to Change UIbutton background color?? I try it on IB, but it doesn't work. only changes it for custom button.

I would like to change the white color on the rounded rect button.

Or instead how to make a custom button whit rounded corners

thanks!

Frade
  • 2,938
  • 4
  • 28
  • 39

6 Answers6

18

Rounded rect button's color can be changed to any color with the background color property in IB as well as through coding, but can not change its color to transparent color easily. For that, you better use a custom button with either rounded image or set layer as demonstrated in the example and don't forget to add Quartz Core framework in you project as well as to import it in your class.

UIBUtton *myBtn = [UIButton buttonWithType:UIbuttonTypeCustom];
myBtn.frame = frame;    //your desired size
myBtn.clipsToBounds = YES;
myBtn.layer.cornerRadius = 5.0f;
[self.view addSubView:myBtn];
2

You may find it difficult to adjust the default button. However you can use any view you want with a custom button.

Here's an article on creating views with rounded corners: http://iphonedevelopment.blogspot.com/2008/11/creating-transparent-uiviews-rounded.html

You also may look at a program called Opacity, which allows you to create a a lot of customized standard iOS interface art/buttons.

http://likethought.com/opacity/

isaac
  • 4,867
  • 1
  • 21
  • 31
  • you are suggesting using a uiview instead of a uibutton!? if so, how do I assign actions?? – Frade Nov 16 '11 at 17:53
  • Ok, i get it! I will use the example you suggest, now I realize that UIbutton inherits from UIview.. – Frade Nov 16 '11 at 18:01
1
UIButton *tagButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

and have a look at this... that my do the trick.. i did it for mine.

Community
  • 1
  • 1
medampudi
  • 399
  • 3
  • 15
0

You can use a custom UIButton with custom images for backgroundimage for each state. Just make the different states of your rounded button in photoshop for example.

Zoleas
  • 4,869
  • 1
  • 21
  • 33
0

You can use Custom button But for that use the image of button of white rounded corners so it will be look like white round rectangle button

Aakil Ladhani
  • 984
  • 9
  • 32
  • 1
    the purpose is to change the color of rounded button. from white to another color, without the need of using an image. currently I'm using images, but I think it will be much more easier, fast and lighter if I just cold change the color.. – Frade Nov 22 '11 at 12:18
0

You should use UIButtonTypeCustom, instead of any other.

Luis Andrés García
  • 5,852
  • 10
  • 43
  • 57