読者です 読者をやめる 読者になる 読者になる

【swift】写真ピッカー UIImagePickerController

swift

if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary){
let imagePickerController = UIImagePickerController()
imagePickerController.sourceType = .photoLibrary
imagePickerController.allowsEditing = true
imagePickerController.delegate = self
present(imagePickerController, animated: true, completion: nil)
}


,UIImagePickerControllerDelegate 追加

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {  
    let image:UIImage = info[UIImagePickerControllerOriginalImage]  as! UIImage  
    let imageData:NSData? = UIImagePNGRepresentation(image) as NSData?  
    picker.dismiss(animated: true, completion: nil)  
}