1
我正在使用以下代碼在iPhone上截取屏幕截圖並將其保存到相冊中。我想要的是一個分享按鈕,可以自動發送此截圖併發送到Facebook。有沒有人有任何想法如何實施?在Facebook上分享屏幕截圖
- (UIImage*)captureView:(UIView *)view
{
CGRect rect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
- (void)saveScreenshotToPhotosAlbum:(UIView *)view
{
UIImageWriteToSavedPhotosAlbum([self captureView:self.view], nil, nil, nil);
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self setUpData];
CGRect frame = self.view.bounds;
frame.size.height -= 90;
self.tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
[self.tableView setBackgroundColor:[UIColor clearColor]];
[self.tableView setDataSource:self];
[self.tableView setDelegate:self];
[self.view addSubview:self.tableView];
UIBarButtonItem *shareBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(saveScreenshotToPhotosAlbum:)];
[self.navigationItem setRightBarButtonItem:shareBtn];
}
好,謝謝,我怎麼把不是進入導航欄上的按鈕? – Steve 2013-04-26 16:56:00
Jus將這段代碼添加到'saveScreenshotToPhotosAlbum:'方法中,它應該可以工作。 – 2013-04-26 16:58:27
我添加了社交框架和導入。現在我可以使用未聲明的標識符'mySLComposerSheet' – Steve 2013-04-26 17:10:51