Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How set background color of a button - xcode

How can I set the background color of a UIButton in Xcode?

I see the property Background and Image in the layout property but i can't set anything in this two. (I can set only image in both not colors)

like image 548
GMX Avatar asked Dec 10 '16 09:12

GMX


People also ask

How do I change the button background in Xcode?

Just scroll a little bit in Attribute Inspector , you can find Background property in view section that will allow you set the backgroundColor for the UIButton . If you want to set backgroundColor of button programatically.

How do I change the background color of a button in Swift?

Add a button on your storyboard, select it Go to it's attribute inspector and select 'Background' property to choose the color.

How do I change the background color in Xcode?

At the top select the attributes inspector. Under the section "View" there should be a spot that says "Background". click that and choose your colour.


1 Answers

Just scroll a little bit in Attribute Inspector, you can find Background property in view section that will allow you set the backgroundColor for the UIButton.

enter image description here

If you want to set backgroundColor of button programatically.

Objective C :

 self.yourButton.backgroundColor = [UIColor redColor]; 

Swift 3 and Swift 4

 self.yourButton.backgroundColor = UIColor.red 

Swift 2.3 or lower

 self.yourButton.backgroundColor = UIColor.redColor() 
like image 150
Nirav D Avatar answered Sep 23 '22 03:09

Nirav D