xcode 使用 Swift 在 iOS 应用程序中上传图片作为个人资料照片
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26413954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
upload an image as profile photo in iOS app with Swift
提问by Martin
in my iOS app I want to upload an image as a profile photo. So, I need something like an Icon to upload the image and then a popup or such a user interface to make a photo by camera or to upload it from the photo album on device. It should be like Facebook.
在我的 iOS 应用程序中,我想上传一张图片作为个人资料照片。所以,我需要一个像图标这样的东西来上传图像,然后一个弹出窗口或这样的用户界面来通过相机制作照片或从设备上的相册上传它。它应该像 Facebook。
I created my app with XCode 6 and Swift. Are there any ideas, solutions or other information?
我使用 XCode 6 和 Swift 创建了我的应用程序。有什么想法、解决方案或其他信息吗?
THX!
谢谢!
采纳答案by Martin
I've solved my problem with following code:
我已经用以下代码解决了我的问题:
func takePhoto(sender: AnyObject) {
if (UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)){
var picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = UIImagePickerControllerSourceType.Camera
var mediaTypes: Array<AnyObject> = [kUTTypeImage]
picker.mediaTypes = mediaTypes
picker.allowsEditing = true
self.presentViewController(picker, animated: true, completion: nil)
}
else{
NSLog("No Camera.")
}
}
func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!) {
let selectedImage : UIImage = image
}