Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Setting UIButton background color only colors the corners

I'm trying to customize my button by changing their colors, but when I use either:

self.loginButton.layer.backgroundColor = [UIColor colorWithRed:0.0 green:157.0/255.0 blue:223.0/255.0 alpha:1.0].CGColor;

or

self.loginButton.backgroundColor = [UIColor colorWithRed:0.0 green:157.0/255.0 blue:223.0/255.0 alpha:1.0];

All I get is this result:

enter image description here

What I want to do is change the white color to blue, any idea what I'm doing wrong?

like image 427
8vius Avatar asked Apr 02 '12 15:04

8vius


People also ask

How do I change the background color in UIButton?

To change the background color of a button in iOS application we need to access the property ' backgroundColor' of the UIButton. We can do this in two ways, programmatically and using the storyboard.

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.

How do I change the background color of a view controller in Xcode?

Find the view or view controller you want to change the background color of. Open it up in the interface builder and open the Attributes Inspector. Find the background color field and set it to the color you want.


2 Answers

You're using a round rect button which is pretty ugly, and pretty hard to customise.

You can create a custom type button and use a background image, or create a custom type button and round the corners and set the background colour of the layer yourself.

If you want to get really fancy there is a nice tutorial here which can give you any-sized gradient type buttons using layers, no image files required.

like image 159
jrturton Avatar answered Sep 18 '22 23:09

jrturton


What's that button type? If you want to customise button, you gotta create a button with [UIButton buttonWithType:UIButtonTypeCustom]

like image 38
Dongsheng Cai Avatar answered Sep 19 '22 23:09

Dongsheng Cai