这个被调用的函数调用一个名为 PopupViewController 的 View Controller 来填充屏幕:
func callSavedPopup() {
let popupViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("PopupViewController") as! PopupViewController
self.addChildViewController(popupViewController)
popupViewController.view.frame = self.view.bounds
popupViewController.userChoiceImage = UIImageView(image: UIImage(named: "CheckMark.png"))
popupViewController.userChoiceLabel.text = "Congrats! Your run was saved!"
self.view.addSubview(popupViewController.view)
popupViewController.didMoveToParentViewController(self)
}
在 PopupViewController.swift 中,有一个图像的导出:
@IBOutlet weak var userChoiceImage: UIImageView!
如何让 userChoiceImage 保存顶部函数中标题为“CheckMark.png”的图像。他们分属两个不同的类(class)
最佳答案
1.) 确保文件名 (CheckMark.png) 的拼写正确! :-)
2.) 确保 Storyboard上默认情况下没有隐藏 socket 。
3.) 确保您的图像已正确连接到 socket (Ctrl + 拖动)
4.)而不是这样做:
popupViewController.userChoiceImage = UIImageView(image: UIImage(named: "CheckMark.png"))
尝试以下操作:
popupViewController.userChoiceImage.image = UIImage(named: "CheckMark.png")
这样你就可以保持 ImageView 的大小、位置等。
关于swift - 为弹出窗口设置 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38622055/