Susanna
Susanna

Reputation: 771

How to make a blue button with white text?

// Make text white... and background blue

[myButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[myButton setBackgroundColor:[UIColor blueColor]];

Should that make a button with white text... and a blue background? It doesn't.

Upvotes: 4

Views: 7649

Answers (2)

hemlocker
hemlocker

Reputation: 1052

It sounds like your button is of the UIButtonTypeRoundedRect type. The link below should answer your question.

Is it even possible to change a UIButtons background color?

What I do however is just not give it a type.

UIButton *myButton = [[UIButton alloc] init];
[myButton setBackgroundColor:[UIColor blueColor]];
[myButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

Doesn't look quite as fancy like that though.

Upvotes: 3

codewarrior
codewarrior

Reputation: 2030

What's the buttonStyle on that button? That'll affect how the color settings make it look. You might try different button styles until you find one that looks right.

Upvotes: 0

Related Questions