250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- keyframes
- 비전공 개발자
- IOS
- react
- javascript
- iPhone
- ipad
- button
- Animation
- 애니메이션
- front-end
- html5
- css3
- MAC
- hover
- HTML
- 비전공자
- effect
- php
- xcode
- 자바스크립트
- 풀스택
- 백엔드
- 개발자
- iOS 개발자
- image
- SWIFT
- jQuery
- CSS
- 프론트엔드
Archives
- Today
- Total
비전공자 개발일기
UIImagePickerControllerDelegate, UINavigationControllerDelegate 본문
728x90
SMALL
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
let imagePicker = UIImagePickerController()
var selectedImage = UIImage()
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self
imageView.backgroundColor = .brown
}
@IBAction func cameraBTN(_ sender: UIButton) {
imagePicker.sourceType = .camera
present(imagePicker, animated: true)
}
@IBAction func photoBTN(_ sender: UIButton) {
imagePicker.sourceType = .photoLibrary
present(imagePicker, animated: true)
}
@IBAction func clearBTN(_ sender: UIButton) {
selectedImage = UIImage()
imageView.image = UIImage()
}
}
extension ViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate, URLSessionDelegate {
// ImagePicker가 활성화됬을 때의 Method
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard let img = info[UIImagePickerController.InfoKey.originalImage] as? UIImage else { return }
selectedImage = img
imageView.image = img
imageView.backgroundColor = .clear
dismiss(animated: true)
}
// ImagePicker 실행 후 취소 버튼을 눌렀을 때의 Method
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true)
}
}
728x90
LIST
'SWIFT' 카테고리의 다른 글
WKWebView Reload Code (0) | 2023.03.04 |
---|---|
Swift Image Upload to Server(PHP) (0) | 2023.03.03 |
WKWebView Phone Call (0) | 2023.03.01 |
WKWebView Component 1(Alert Event, go Back, go Forward) (0) | 2023.02.27 |
Device ID(UUID) (0) | 2023.02.26 |