0

I need a quick way to change the color of an UIButton live (in response to a delegate call) . So the button is drawn with a white background (standard) then when a delegate call comes it needs to change to a blue/red background.

I tried :

   btn.backgroundColor = [UIColor redColor];
        [btn setNeedsDisplay];

This doesn't work...

Also it would be a good ideea to change the color of the button text... How is this done????

user1028028
  • 6,323
  • 9
  • 34
  • 59

2 Answers2

2

Try using it like this :

[button setBackgroundColor:someColor forState:UIControlStateNormal];

Did it work for you .. ? I am assuming you have made your button a custom button type. If it worked, you may want to consider, accepting the answer

Shailesh
  • 3,072
  • 3
  • 24
  • 33
0

First make your UIButton type Custom..

UIButton* myButton = [UIButton buttonWithType:UIButtonTypeCustom];

[myButton setbackgroundColor:[UIColor blueColor] forState: UIControlStateNormal];
[myButton setTitleColor:[UIColor blueColor] forState: UIControlStateNormal];
BhushanVU
  • 3,455
  • 1
  • 24
  • 33