I am working on my application to add twitter feature to share the screenshot of my current viewcontroller. Is there any in built method that I can use ?
Asked
Active
Viewed 166 times
1 Answers
1
This answer has the following method to create a screenshot:
- (UIImage *)captureView:(UIView *)view {
CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);
[view.layer renderInContext:ctx];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
It returns a UIImage, which you can then use like this:
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
tweetSheet.image = [self captureView:self.view]; // or self.navigationController.view
[self presentViewController:tweetSheet animated:YES completion:^{}];

Community
- 1
- 1

Scott Berrevoets
- 16,921
- 6
- 59
- 80
-
@Scoot, could please also look at my other question http://stackoverflow.com/questions/16485895/resizing-uiimage-to-post-to-twitter-sheet-ios – casillas May 10 '13 at 15:51