如何导入一张图片并将其设置为 UIIMageView。然后再用另一个 UIIMageView?
How to import one image and set it as a UIIMageView. Then again with another UIIMageView?
所以目前我已经设置好了,我可以在其中导入图像并将其设置为 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)
}
你应该问你的第一个UIImageView是否为null,然后在那个里面加载图片,如果不是,在第二个UIImageView中加载图片。
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
if picture1.image == nil {
picture1.image = image
}else {
picture2.image = image
}
}
所以目前我已经设置好了,我可以在其中导入图像并将其设置为 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)
}
你应该问你的第一个UIImageView是否为null,然后在那个里面加载图片,如果不是,在第二个UIImageView中加载图片。
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
if picture1.image == nil {
picture1.image = image
}else {
picture2.image = image
}
}