如何像Apple一样用水平滑块创建UIAlertControllerStyleActionSheet? (图像)

时间:2016-05-19 14:56:53

标签: ios objective-c uiactionsheet uialertcontroller

我想在我的应用中实施社交分享 - 通过UIAlertControllerStyleActionSheet

并希望通过横向滑动在一行中添加Facebook,Twitter,Google +等图标 - 与Apple一样,例如共享Notes app。

我知道如何添加取消按钮)

UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"Share" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];

但不知道如何使用图标添加水平视图。

你能帮帮我吗?

enter image description here

1 个答案:

答案 0 :(得分:1)

正如rmaddy所述,它是UIActivityViewController

我使用它的例子:

// creating an anchor point for UIActivityViewController than will be used on iPad
CGRect pointRect = [[notification.userInfo objectForKey:@"cellRect"] CGRectValue];
CGRect sourceRect = CGRectMake(pointRect.origin.x, pointRect.origin.y + pointRect.size.height, 5, 5);
UIView *sourceView = [[UIView alloc] initWithFrame:sourceRect];
[self.view addSubview:sourceView];

// prepare object to share
NSString *textToShare = @"Text to share";
NSURL *webSite = [NSURL URLWithString:@"http://website.com"];
NSArray *itemToShare = @[textToShare, webSite];

// initializing custom UIActivity for "Reddit"
RedditActivity *reddit = [[RedditActivity alloc] init];

// initializing popover UIActivityViewController
UIActivityViewController *controller = [[UIActivityViewController alloc]
        initWithActivityItems:itemToShare
        applicationActivities:[NSArray arrayWithObjects:reddit, nil]];

// add anchor point for iPad
if ( [controller respondsToSelector:@selector(popoverPresentationController)] ) {
    controller.popoverPresentationController.sourceView = sourceView;
}

// excluded system UIActivity items
controller.excludedActivityTypes = @[UIActivityTypePostToWeibo,
     UIActivityTypePrint,
     UIActivityTypeAssignToContact,
     UIActivityTypeSaveToCameraRoll,
     UIActivityTypeAddToReadingList,
     UIActivityTypePostToFlickr,
     UIActivityTypePostToVimeo,
     UIActivityTypePostToTencentWeibo,
     UIActivityTypeAirDrop,
     UIActivityTypeOpenInIBooks];

// show popover UIActivityViewController
[self presentViewController:controller animated:YES completion:nil];