如何使用 UIImagePickerController 将图像添加到推文? [英] How I can use a UIImagePickerController to add an image to a tweet?
问题描述
我是 iOS 开发的新手,所以我很困惑.我有一个 ViewController,在这个 ViewController 中有很多 UIButton.如何使用 addImage
打开选择器并将图像添加到推文中?PS:我正在使用故事板.
I'm new to iOS development so I'm confused. I have a ViewController, in this ViewController there are many UIButtons. How I can open the picker and add the image to the tweet using addImage
?
PS: I'm using Storyboard.
谢谢和抱歉我的英语... :)
Thanks and sorry for my english... :)
推荐答案
当按钮被按下时,你想要做的事情是:
when the button is pressed, you want to do something like:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
}
您需要实现委托方法.主要是:
you need to implement the delegate methods. the main one is:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSData *imageData = UIImagePNGRepresentation(image);
// do twitter stuff here....
[self dismissModalViewControllerAnimated:YES];
}
for more information, see the docs: http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/PickinganItemfromthePhotoLibrary.html#//apple_ref/doc/uid/TP40010408-SW1
这篇关于如何使用 UIImagePickerController 将图像添加到推文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!