使用一个图像选择器的三个按钮,图像不更新

时间:2020-06-23 19:01:42

标签: swift xcode

我开始学习Swift,并尝试在用户触发三个按钮之一时使用一个图像选择器更改按钮图像来实现。

我观看了在线资源,并了解了如何使用一个图像选择器来更改一个按钮图像

但是现在我有三个按钮,每个按钮都应该能够使用图像选择器并更改自己的按钮图像。

我的解决方案是每次单击按钮并调用图像选择器时,我将函数之外的UIImage设置为等于信息图像

同时,知道图像选择器是由于按下按钮而触发的,所以我在按钮(IBAction函数)中放了一行带有UIImage的set-button-image。

下面是我的源代码。我写的某种方式不会正确更新按钮的图像。

让我知道是否有任何信息丢失或混乱。任何建议或知识都会有所帮助,谢谢。

sourceCode1

sourceCode2

main page

after clicking the add button the library shows

after select image, the button image shows all white

after clicking the white part, the image somehow shows

If I click another button, the button change like the first button???

0 个答案:

没有答案