Bogdan Laukhin Bogdan Laukhin - 6 months ago 64
Objective-C Question

How to create UIAlertControllerStyleActionSheet with horizontal slider as Apple does? (image)

I want to implement social sharing in my app - via

UIAlertControllerStyleActionSheet
.

And want to add icons of Facebook, Twitter, Google+ etc in one line with horizontal swiping - the same way as Apple do, e.g. in sharing for
Notes
app.

I know how to add Cancel button yet )

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];


But don't know how to add horizontal view with icons.

Could you please help me out?

enter image description here

Answer

As rmaddy stated it was an UIActivityViewController

My example of using it:

// 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];