xcode 如何编写共享按钮?代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25293968/
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
How do I program a share button ? xcode
提问by Deniz Yazar
I found a repository on gifthub that is exactly what i was looking for. Can you help me how to code this to work with a single button. I don't enough experience yet with ios programmin to do this. I almost finished building my first app, but i need help with this.
我在gifthub 上找到了一个存储库,这正是我要找的。你能帮我如何编写代码以使用单个按钮吗?我还没有足够的 ios 编程经验来做到这一点。我几乎完成了我的第一个应用程序的构建,但我需要这方面的帮助。
Thanks in advance
提前致谢
回答by tnylee
For a beginner I suggest this.. Its much easier. Just a few lines of code.
对于初学者,我建议这样做..它更容易。只需几行代码。
- (IBAction)shareButtonPressed:(id)sender {
NSLog(@"shareButton pressed");
NSString *texttoshare = @"text to share";
UIImage *imagetoshare = [UIImage imageNamed:@"beck.png"];
NSArray *activityItems = @[texttoshare, imagetoshare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypePostToTwitter, UIActivityTypePostToWeibo];
[self presentViewController:activityVC animated:TRUE completion:nil];
}