Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 未删除UIButton禁用状态的图像_Swift_Uibutton - Fatal编程技术网

Swift 未删除UIButton禁用状态的图像

Swift 未删除UIButton禁用状态的图像,swift,uibutton,Swift,Uibutton,我制作了一个按钮,可以切换自己的isEnabled,它根据这个状态更新按钮的标题和图像 myButton.setTitle("Enabled Title", for: .normal) myButton.setImage(UIImage(named: "enabled_resource_name"), for: .normal) myButton.setTitle("Disabled Title", for: .disabled) myButton.setImage(nil, for: .di

我制作了一个按钮,可以切换自己的
isEnabled
,它根据这个状态更新按钮的标题和图像

myButton.setTitle("Enabled Title", for: .normal)
myButton.setImage(UIImage(named: "enabled_resource_name"), for: .normal)

myButton.setTitle("Disabled Title", for: .disabled)
myButton.setImage(nil, for: .disabled)
我的按钮的
isEnabled
切换良好。标题也因此而改变。 但我发现了一个关于改变形象的奇怪问题

enabled
disabled
的情况下,图像
UIImage(名为:“enabled\u resource\u name”)
不会被删除

但它有一点变化。禁用后,图像变得有点透明。在
禁用
启用
的情况下,它确实可以正常工作

为什么会发生这种情况?

尝试设置
UIImage()
而不是
nil
,例如:

myButton.setImage(UIImage(), for: .disabled)

这是正确的,但我认为有一个错误,有人应该雷达它也许?