在iOS上发布推文截图

时间:2012-07-01 08:46:06

标签: iphone objective-c twitter image

尝试在我的应用程序中发布一条推文中的屏幕截图..到目前为止我已经将它保存到库中但是我需要发推文...这里是一个截图和空的twitter帖子...

- (IBAction)savephoto:(id)sender {

// Returns 1024x768 for iPad Retina
CGSize screenDimensions = [[UIScreen mainScreen] applicationFrame].size;

// Create a graphics context with the target size
// (last parameter takes scale into account)
UIGraphicsBeginImageContextWithOptions(screenDimensions, NO, 0);

// Render the view to a new context
CGContextRef context = UIGraphicsGetCurrentContext();
[customview.layer renderInContext:context];

// Save to Camera Roll
CGRect contentRectToCrop = CGRectMake(18, 14, 602, 460);
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();

CGImageRef imageRef = CGImageCreateWithImageInRect([screenshot CGImage], contentRectToCrop);
UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
UIImageWriteToSavedPhotosAlbum(croppedImage, self, nil, nil);

UIGraphicsEndImageContext();

.........

- (IBAction)tweetphoto:(id)sender {

TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
[twitter setInitialText:@"Enter tweet here!"];
[twitter addImage:[UIImage imageNamed:@""]];

........

无法弄清楚要在imageNamed中输入什么...

2 个答案:

答案 0 :(得分:2)

[...]
UIImage* croppedImage = [UIImage imageWithCGImage:imageRef];

TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
[twitter setInitialText:@"Enter tweet here!"];
[twitter addImage:croppedImage];

UIGraphicsEndImageContext();

答案 1 :(得分:1)

为什么不使用已经创建的“裁剪图像”对象。你不需要使用

创建另一个

[UIimage imageName:@“”];

有用吗?