swift - 为弹出窗口设置 UIImageView

标签 swift uiimageview popup uiimage

这个被调用的函数调用一个名为 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/

相关文章:

ios - swift 2 中翻转动画的工作原理

ios - +[NSURL URLWithString :] returning nil

ios - 尝试使用 reverseGeocodeLocation,但未执行 completionHandler 代码

ios - 创建一个基于步骤的 View Controller 流程

iphone - 使动态 ImageView 可点击

javascript - 如何在页面加载javascript之前弹出一些内容

Python Qt 如何从 QMainWindow 打开弹出的 QDialog

swift - 拍照允许我在 BSImagePicker Swift ios 中选择超过 maxNumberOfSelections

swift - 在 AppDelegate 中设置初始 View Controller 时完全黑屏

jquery - 在 jQuery Mobile 的弹出窗口中打开外部页面