在 Storyboard 中,我定义了 UIButton
必须由程序启用/禁用。它的默认状态没有背景图片,并且标题为“默认”。如果它的禁用状态既没有背景图像,也没有不同的标题“禁用”,我通过程序在两种状态之间切换,UIButton
按预期在模拟器和设备中以两种状态显示:
但是,如果我只为禁用状态分配背景图像,UIButton
按预期显示为禁用状态,但默认状态现在有透明图像和背景图像,即仅显示标题:
我希望将背景图像分配给禁用状态不会将分配更改为默认状态。我错了吗?
最佳答案
重新启用时将 backgroundImage 设置为 nil:
[myButton setBackgroundImage:nil forState:UIControlStateNormal];
[myButton setBackgroundImage:nil forState:UIControlStateDisabled];
这使我的按钮再次显示正常。
补充阅读:http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIButton_Class/UIButton/UIButton.html#//apple_ref/doc/c_ref/UIButtonType
关于ios - UIButton:将背景图像设置为禁用状态会更改默认状态的显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15481204/