1、创建按钮,并绑定activity方法
// 按钮
self.btn = [UIButton buttonWithType:UIButtonTypeCustom];
self.btn.frame = CGRectMake(100, 100, 200, 200);
self.btn.backgroundColor = [UIColor orangeColor];
[self.btn setTitle:@"Activity" forState:UIControlStateNormal];
// 绑定方法
[self.btn addTarget:self action:@selector(activity) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:self.btn];
2、activity方法
#pragma activity方法
- (void)activity{
// 文字
NSString *str = @"这是activity";
// 链接
NSURL *URL = [NSURL URLWithString:@"http://www.baidu.com"];
// 创建UIActivityViewController
// ActivityItems参数
// ActivityItems参数
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[str, URL] applicationActivities:nil];
// 不显示的activity
activityVC.excludedActivityTypes = @[UIActivityTypePostToFacebook];
[self presentViewController:activityVC animated:YES completion:nil];
}
3、效果
4、excludedActivityTypes
默认UIActivityViewController 将显示所有可用于所提供内容的服务,但我们也可以排除特定的 Activity 类型。
例如:不要显示FaceBook
activityViewController.excludedActivityTypes = @[UIActivityTypePostToFacebook];
所有activity:
UIKIT_EXTERN UIActivityType const UIActivityTypePostToFacebook NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;
UIKIT_EXTERN UIActivityType const UIActivityTypePostToTwitter NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;
UIKIT_EXTERN UIActivityType const UIActivityTypePostToWeibo NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED; // SinaWeibo
UIKIT_EXTERN UIActivityType const UIActivityTypeMessage NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;
UIKIT_EXTERN UIActivityType const UIActivityTypeMail NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;
UIKIT_EXTERN UIActivityType const UIActivityTypePrint NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;
UIKIT_EXTERN UIActivityType const UIActivityTypeCopyToPasteboard NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;
UIKIT_EXTERN UIActivityType const UIActivityTypeAssignToContact NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;
UIKIT_EXTERN UIActivityType const UIActivityTypeSaveToCameraRoll NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;
UIKIT_EXTERN UIActivityType const UIActivityTypeAddToReadingList NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
UIKIT_EXTERN UIActivityType const UIActivityTypePostToFlickr NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
UIKIT_EXTERN UIActivityType const UIActivityTypePostToVimeo NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
UIKIT_EXTERN UIActivityType const UIActivityTypePostToTencentWeibo NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
UIKIT_EXTERN UIActivityType const UIActivityTypeAirDrop NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
UIKIT_EXTERN UIActivityType const UIActivityTypeOpenInIBooks
每个 Activity 类型都支持好多种不同的数据类型。例如,一条 Tweet 可能由 NSString 以及一个附加的图像 和/或 URL 所组成。