Skip to content

Instantly share code, notes, and snippets.

@ctkqiang
Last active May 24, 2020 12:35
Show Gist options
  • Save ctkqiang/20e3c9e9a16e67f476ff3a1feeda579c to your computer and use it in GitHub Desktop.
Save ctkqiang/20e3c9e9a16e67f476ff3a1feeda579c to your computer and use it in GitHub Desktop.
import UIKit
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
@IBOutlet weak var ImageDisplay: UIImageView!
@IBOutlet weak var CameraButton: UIButton!
@IBOutlet weak var LibraryButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
print("Out Of Memory")
}
@IBAction func CameraButton(_ sender:UIButton) {
print("hi")
}
// Mark: Action:
@IBAction func PhotoLibraryAction(sender: UIButton) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .photoLibrary
// PRevious version ``` presentViewController(picker, animated: true, completion: nil)```
present(picker, animated: true, completion: nil)
}
@IBAction func CameraAction(sender: UIButton) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .camera
present(picker, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
ImageDisplay.image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage;
dismiss(animated: true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment