为Popup设置UIImageView

时间:2016-07-27 19:54:29

标签: swift uiimageview popup uiimage

这个被调用的函数调用一个名为PopupViewController的视图控制器填充屏幕:

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”的图像。他们分为两个不同的班级

1 个答案:

答案 0 :(得分:0)

1。)确保文件名(CheckMark.png)的拼写正确! : - )

2。)确保故事板上默认不隐藏插座。

3.确保您的图像正确连接到插座(按住Ctrl键+拖动)

4。)而不是:

 popupViewController.userChoiceImage = UIImageView(image: UIImage(named: "CheckMark.png"))

尝试以下方法:

popupViewController.userChoiceImage.image = UIImage(named: "CheckMark.png")

这样可以保持ImageView的大小,定位等。