Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the button text color when selected

I have a custom button and I am setting the different image when it is highlighted. Now, I want to change the color of the text on the button when button is highlighted. Is it possible to do this?

like image 466
Abhinav Avatar asked May 20 '11 21:05

Abhinav


People also ask

How do I change the color of my text buttons?

Use a semi-colon to separate the different style elements in the HTML button tag. Type color: in the quotation marks after "style=". This element is used to change the text color in the button. You can place style elements in any order in the quotation markers after "style=".

How do I change the text color of a button in react?

You can use a Button from react-native like this and can also pass the color prop. For complex and custom buttons you can create it by your own styles using Touchables which are given by react-native you don't have to use any third-party libraries for that. The first code doesn't change the text colour.

How do you change the color of text in HTML?

To set the font color in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property color. HTML5 do not support the <font> tag, so the CSS style is used to add font color.


2 Answers

You can do it this way:

[myButton setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];
like image 190
Nick Weaver Avatar answered Oct 24 '22 16:10

Nick Weaver


Swift version:

myButton.setTitleColor(UIColor.greenColor(), forState: UIControlState.Highlighted)
like image 37
King-Wizard Avatar answered Oct 24 '22 18:10

King-Wizard