Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.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
Swiftui 在按钮中,单击“将图像添加到”按钮_Swiftui - Fatal编程技术网

Swiftui 在按钮中,单击“将图像添加到”按钮

Swiftui 在按钮中,单击“将图像添加到”按钮,swiftui,Swiftui,我有一个覆盖了背景图像和文本的按钮,当我单击按钮时,我想从按钮中删除文本并替换为图像。如何在添加图像的操作中获取对按钮的引用,我陷入了困境 Button(action: { print("3 clicked") self.background(Image("cross100x100")) self.disableButton = true }) { Text("Button text") } .disabled(disableButton) 上面的代码不起作用 当我点击按钮时,

我有一个覆盖了背景图像和文本的按钮,当我单击按钮时,我想从按钮中删除文本并替换为图像。如何在添加图像的操作中获取对按钮的引用,我陷入了困境

Button(action: {
  print("3 clicked")
  self.background(Image("cross100x100"))
  self.disableButton = true
}) {
  Text("Button text")
}
.disabled(disableButton)
上面的代码不起作用

当我点击按钮时,我想从按钮中删除文本,然后 替换为图像

我不确定为什么这里有
disableButton
,但是对于上面的方法可能如下

@State private var clicked=false
...
按钮(操作:{
self.clicked=true
}) {
如果单击self.click{
图像(“cross100x100”)
}否则{
文本(“按钮文本”)
}
}