问题描述
@IBAction func ProfilePicclicked(_ sender: UIButton) {
let imagePickercontroller = UIImagePickerController()
imagePickercontroller.delegate = self
let alert = UIAlertController(title: "Do You Want to Chage your Profile Picture?",message: "Choose any Option",preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Camera",style: .default,handler: { [self] (action:UIAlertAction) in
if UIImagePickerController.isSourceTypeAvailable(.camera){
imagePickercontroller.sourceType = .camera
self.present(imagePickercontroller,animated: true,completion: nil)
}else{
print("Camera not Available")
}
}))
alert.addAction(UIAlertAction(title: "Photo Library",handler: { (action:UIAlertAction) in
imagePickercontroller.sourceType = .photoLibrary
self.present(imagePickercontroller,completion: nil)
}))
self.present(alert,animated: true)
alert.addAction(UIAlertAction(title: "Cancel",style: .cancel,handler: nil))
}
func imagePickerController(_ picker: UIImagePickerController,didFinishPickingMediawithInfo info: [UIImagePickerController.InfoKey : Any]) {
let image = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
profilePicImageView.image = image
let imagePath = try! FileManager.default.url(for: .documentDirectory,in: .userDomainMask,appropriateFor: nil,create: true).appendingPathComponent("image.jpg")
print("Image path is \(imagePath)")
picker.dismiss(animated: true,completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.dismiss(animated: true,completion: nil )
}
这是我选择图片的代码 我正在从用户那里获取图像并将图像设置为“profilePicImageView.image”
当用户选择图像时,我想确定其位置。 :https://i.stack.imgur.com/0K0Qs.png
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)