Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.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
Iphone 在Swift的if和else语句中更改UIBarButtonIcon_Iphone_Swift_Uibarbuttonitem - Fatal编程技术网

Iphone 在Swift的if和else语句中更改UIBarButtonIcon

Iphone 在Swift的if和else语句中更改UIBarButtonIcon,iphone,swift,uibarbuttonitem,Iphone,Swift,Uibarbuttonitem,在If和else语句中,我想更改我的Barbuttonite的自定义图像。默认情况下,我已经有一个自定义图像,但我知道在某些情况下,它会更改为另一个自定义图像。如果您的图像位于Assets.xcsets中,则可以执行以下操作: if something { yourBarButtonItem.image = imagename } else { yourBarButtonItem.image = anotherimagename } 这应该行得通。否则,如果您的图像仅位

在If和else语句中,我想更改我的Barbuttonite的自定义图像。默认情况下,我已经有一个自定义图像,但我知道在某些情况下,它会更改为另一个自定义图像。

如果您的图像位于Assets.xcsets中,则可以执行以下操作:

if something {

    yourBarButtonItem.image = imagename

} else {

    yourBarButtonItem.image = anotherimagename

}
这应该行得通。否则,如果您的图像仅位于项目中的文件夹中,则可以:

if something {

    yourBarButtonItem.image = UIImage(named: "imagename.extension")

} else {

    yourBarButtonItem.image = UIImage(named: "imagename.extension")

}
非常感谢:)@Lucas Palian