如何导入一个图像并将其设置为UIIMageView。再用另一个UIIMageView?

问题描述 投票:0回答:1

所以目前我已经设置了导入图像并将其设置为UIImageView的设置。我正在寻找的是帮助如何再次这样做。香港专业教育学院尝试了一些事情,但当我再次这样做时,却无法获得任何实际工作。我还添加了一个照片示例。

Photo Example

@IBAction func importImg(_ sender: Any) {
    //import image 1
    let picture = UIImagePickerController()
    picture.delegate = self
    picture.allowsEditing = false
    picture.sourceType = UIImagePickerControllerSourceType.photoLibrary
    self.present(picture, animated: false, completion: nil)
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

    if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {

        picture1.image = image
    }

    self.dismiss(animated: true, completion: nil)
}
swift import photo
1个回答
0
投票

您应该询问您的第一个UIImageView是否为null,然后加载图像,如果没有,则在第二个UIImageView中加载图像。

if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {

    if picture1.image == nil {
        picture1.image = image
    }else {
        picture2.image = image
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.