0

I have used below code to show action sheet with Tweet, Facebook and Cancel button.

- (void)shareApp:(id)sender {
    NSString *strCancel = NSLocalizedString(@"Cancel", nil);
    NSString *strTweet = NSLocalizedString(@"Tweet", nil);
    NSString *strFacebook = NSLocalizedString(@"Facebook", nil);

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Share your app", nil) message:nil preferredStyle:UIAlertControllerStyleActionSheet];

    // Create the actions.
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:strCancel style:UIAlertActionStyleCancel
                                                         handler:^(UIAlertAction *action) {
                                            NSLog(@"Cancel action occured");
                                }];

    UIAlertAction *tweetAction = [UIAlertAction actionWithTitle:strTweet style:UIAlertActionStyleDefault
                                                        handler:^(UIAlertAction *action) {
                                                            NSLog(@"Tweet action here");
                                                        }];

    UIAlertAction *facebookAction = [UIAlertAction actionWithTitle:strFacebook style:UIAlertActionStyleDefault
                                                        handler:^(UIAlertAction *action) {
                                                            NSLog(@"Facebook action here");
                                                        }];

    // Add the actions.
    [alertController addAction:cancelAction];
    [alertController addAction:tweetAction];
    [alertController addAction:facebookAction];

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

Screenshot

Now, I want to add custom view i.e. logo + tweet on each element of action sheet.

Desired screenshot

How can this be implemented?

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
  • http://stackoverflow.com/questions/29226050/how-can-i-customize-uialertaction-in-uialertcontroller-for-ios8 – Vizllx Jun 03 '15 at 10:30

1 Answers1

3

I got the solution through your code.Just refer the below coding

 NSString *strCancel = NSLocalizedString(@"Cancel", nil);
 NSString *strTweet = NSLocalizedString(@"Tweet", nil);
 NSString *strFacebook = NSLocalizedString(@"Facebook", nil);

 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Share your app", nil) message:nil preferredStyle:UIAlertControllerStyleActionSheet];

 UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:strCancel style:UIAlertActionStyleCancel
 handler:^(UIAlertAction *action) {
 NSLog(@"Cancel action occured");
 }];

UIAlertAction *tweetAction = [UIAlertAction actionWithTitle:strTweet style:UIAlertActionStyleDefault
                                                    handler:^(UIAlertAction *action) {
                                                        NSLog(@"Tweet action here");
                                                    }];

UIAlertAction *facebookAction = [UIAlertAction actionWithTitle:strFacebook style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction *action) {

                                                           NSLog(@"Facebook action here");


                                                       }];

UIImage *accessoryImage = [UIImage imageNamed:@"Twitter.jpg"];
[tweetAction setValue:accessoryImage forKey:@"image"];
UIImage *accessoryFBImage = [UIImage imageNamed:@"Facebook.png"];
[facebookAction setValue:accessoryFBImage forKey:@"image"];


[alertController addAction:tweetAction];
[alertController addAction:facebookAction];
[alertController addAction:cancelAction];

[self presentViewController:alertController animated:YES
                                      completion:nil];
user3182143
  • 9,459
  • 3
  • 32
  • 39