我一直在使用以下代码来选择图像并通过UIImageView显示它:
class ViewController UIViewContoller, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var imageView: UIImageView!
let imagePicker = UIImagePickerController()
override func viewDidLoad(){
super.viewDidLoad()
imagePicker.delegate = self
}
@IBAction func loadImage(_ sender: Any){
imagePicker.allowsEditing = false
imagePicker.sourceType = .photoLibrary
present(imagePicker, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]){
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage{
imageView.contentMode = .scaleAspectFit
imageView.image = pickedImage
}
dismiss(animated: true completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController){
dismiss(animated: true, completion: nil)
}
}
如何使用UIImagePickerController类选择多个图像和视频并将其显示在集合视图中?
答案 0 :(得分:0)
如何使用UIImagePickerController类选择多个图像和视频
不能。 UIImagePickerController允许用户选择一个图片/视频。