From 1167714e6b987e73abc9d9b46f930ec69cfbcab7 Mon Sep 17 00:00:00 2001 From: mehak mansoori Date: Sun, 28 Jan 2024 10:50:35 +0530 Subject: [PATCH] swift --- .vscode/settings.json | 2 +- ViewController.swift | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 ViewController.swift diff --git a/.vscode/settings.json b/.vscode/settings.json index 6f3a291..f673a71 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "liveServer.settings.port": 5501 + "liveServer.settings.port": 5502 } \ No newline at end of file diff --git a/ViewController.swift b/ViewController.swift new file mode 100644 index 0000000..1731b10 --- /dev/null +++ b/ViewController.swift @@ -0,0 +1,26 @@ +import UIKit + +class MainViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { + + // Connect this to your "Add Story" button in Interface Builder + @IBAction func addStoryButtonTapped(_ sender: UIButton) { + let imagePicker = UIImagePickerController() + imagePicker.delegate = self + imagePicker.sourceType = .camera // or .photoLibrary if you prefer + present(imagePicker, animated: true, completion: nil) + } + + // MARK: - UIImagePickerControllerDelegate + + func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { + if let image = info[.originalImage] as? UIImage { + // Handle the selected image here, you can save it, process it, or upload it + // You might want to navigate the user to another screen for editing or adding captions + } + picker.dismiss(animated: true, completion: nil) + } + + func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { + picker.dismiss(animated: true, completion: nil) + } +}