2013-10-30 30 views
54

我已經在大多數的支持iOS的7 的iOS應用程序看到股票期權的格式(如下圖)是否有可用於實現這一份額選項默認代碼/框架如圖所示它在下面的圖片?默認共享中的iOS 7

+0

看看這個教程:http://www.appcoda.com/ios7-airdrop-programming-tutorial/ – Sakiboy

回答

52

你要找的是UIActivityViewController

既然你問了一個普遍的問題,我不能做多給你一個鏈接到圖像中你貼的是UIActivitiyViewController this is a link類文檔的documentation

4

的控制器

1

UIActivityViewController是什麼你正在尋找。

可以指定的項目或應用

UIActivityViewController *actCont = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil]; 
15

除了公認的答案,一小塊的示例代碼

- (void)shareText:(NSString *)text andImage:(UIImage *)image andUrl:(NSURL *)url 
    { 
     NSMutableArray *sharingItems = [NSMutableArray new]; 
     if (text) { 
      [sharingItems addObject:text]; 
     } 
     if (image) { 
      [sharingItems addObject:image]; 
     } 
     if (url) { 
      [sharingItems addObject:url]; 
     } 
     UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil]; 
     [self presentViewController:activityController animated:YES completion:nil]; 
    } 

呼叫shareText,留下你不想在nil分享的東西。

[self shareText:@"Hello world" andImage:nil andUrl:nil]; 
1

只需使用以下代碼默認共享。可以能夠添加更多的項目到shareItems陣列按您的要求。

NSMutableArray *shareItems = [[NSMutableArray alloc] initWithObjects: 
           @"Hello", 
           [UIImage imageNamed:@"your_image.png"], 
           @"http://google.com/", nil]; 
[self shareItemToOtherApp:shareItems]; 

以下方法是默認共享文本或圖片到其他應用程序: -

-(void)shareItemToOtherApp:(NSMutableArray *)shareItems{ 
    UIActivityViewController *shareController = [[UIActivityViewController alloc] 
               initWithActivityItems: shareItems applicationActivities :nil]; 

    [shareController setValue:@"Sharing" forKey:@"subject"]; 
    shareController.excludedActivityTypes = @[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeSaveToCameraRoll]; 

    shareController.completionHandler = ^(NSString *activityType, BOOL completed) 
    { 
     //NSLog(@" activityType: %@", activityType); 
     //NSLog(@" completed: %i", completed); 
    }; 

    [self presentViewController: shareController animated: YES completion: nil]; 
} 

如果你想那麼自定義共享表使用下面的代碼。對於這一點,你必須輸入<Social/Social.h>框架。

-(void)shareOnFacebook:(id)sender { 
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) 
    { 
     SLComposeViewController *faceSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; 
     // NSLog(@"%@", messageField.text);//This returns the appropriate string 
     [faceSheet setInitialText:@"Hellooooooo"]; 
     //The facebook VC appears, but initial text is not set to messageField.text 
     [self presentViewController:faceSheet animated:YES completion:nil]; 
    } 
    else 
    { 
     NSLog(@"Please first install Application and login in Facebook"); 
    } 
} 

-(void)shareOnTwitter:(id)sender { 
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) 
    { 
     SLComposeViewController *tweetSheet = [SLComposeViewController 
               composeViewControllerForServiceType:SLServiceTypeTwitter]; 
     [tweetSheet setInitialText:@"Hello"]; 
     [self presentViewController:tweetSheet animated:YES completion:nil]; 
    } 
    else{ 
     NSLog(@"Please first install Application and login in Twitter"); 
    } 
} 

希望,這就是你要找的。任何擔心都會回到我身上。 :)