Reinhard Männer
Reinhard Männer

Reputation: 15257

UIButton: Setting background image to the disabled state changes display of the default state

In Storyboard I defined a UIButton that has to be enabled/disabled by program. Its default state has no background image, and the title "Default". If its disabled state has neither a background image, and just a different title "Disabled", and I switch between both states by program, the UIButton is displayed in both states in the simulator and a device as expected:enter image description here
However, if I assign only to the disabled state a background image, the UIButton is displayed in the disabled state as expected, but the default state has now a transparent image and background image, i.e., only the title is displayed:
enter image description here
I expected that assigning a background image to the disabled state does not change the assignment to the default state. Am I wrong?

Upvotes: 1

Views: 3948

Answers (1)

rog
rog

Reputation: 5361

Set the backgroundImage to nil when re-enabling:

[myButton setBackgroundImage:nil forState:UIControlStateNormal];

[myButton setBackgroundImage:nil forState:UIControlStateDisabled];

This makes my button appear normal again.

Additional Reading: http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIButton_Class/UIButton/UIButton.html#//apple_ref/doc/c_ref/UIButtonType

Upvotes: 3

Related Questions