iOS/코드조각

[iOS, Swift] UIImagePickerController 이미지 선택 화면 띄우기

검은참깨두유vm 2022. 8. 21. 11:20
반응형

iOS 15.5, Xcode 13.31, Swift 5, UIKit 환경에서 진행했습니다.

 

class UIImagePickerViewController: UIViewController {
    
    let imagePickerController = UIImagePickerController()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        imagePickerController.delegate = self
        imagePickerController.sourceType = .photoLibrary
        
        view.backgroundColor = .white
        self.present(imagePickerController, animated: true)
    }
    
}

extension UIImagePickerViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        self.dismiss(animated: true)
    }
    
    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        self.dismiss(animated: true)
    }
    
}

 

 

 

반응형