Adding Images to UIActionSheet buttons as in UIDocumentInteractionController

后端 未结 12 1617
我寻月下人不归
我寻月下人不归 2020-11-30 19:39

Is it possible to add an image to the buttons of the UIActionSheet as seen in UIDocumentInteractionController? If so, please let me know how it is

12条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 20:17

    - (IBAction)actionSheetButtonPressed:(id)sender {
    UIAlertController * view=   [UIAlertController
                                 alertControllerWithTitle:@"Share "
                                 message:@"Select your current status"
                                 preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction* online = [UIAlertAction
                             actionWithTitle:@"Facebook"
                             style:UIAlertActionStyleDefault
                             handler:^(UIAlertAction * action)
                             {
                                 //Do some thing here
                                 [view dismissViewControllerAnimated:YES completion:nil];
                             }];
    UIAlertAction* offline = [UIAlertAction
                              actionWithTitle:@"Google+"
                              style:UIAlertActionStyleDefault
                              handler:^(UIAlertAction * action)
                              {
                                  [view dismissViewControllerAnimated:YES completion:nil];
                              }];
    UIAlertAction* doNotDistrbe = [UIAlertAction
                                   actionWithTitle:@"LinkedIn"
                                   style:UIAlertActionStyleDefault
                                   handler:^(UIAlertAction * action)
                                   {
                                       [view dismissViewControllerAnimated:YES completion:nil];
                                   }];
    UIAlertAction* away = [UIAlertAction
                           actionWithTitle:@"Twitter"
                           style:UIAlertActionStyleDestructive
                           handler:^(UIAlertAction * action)
                           {
                               [view dismissViewControllerAnimated:YES completion:nil];
    
                           }];
    UIAlertAction* cancel = [UIAlertAction
                         actionWithTitle:@"Cancel"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                         }];
    
    [online setValue:[[UIImage imageNamed:@"facebook.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"];
    [offline setValue:[[UIImage imageNamed:@"google-plus.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"];
    [doNotDistrbe setValue:[[UIImage imageNamed:@"linkedin.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"];
    [away setValue:[[UIImage imageNamed:@"twitter.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"];
    
    [view addAction:online];
    [view addAction:away];
    [view addAction:offline];
    [view addAction:doNotDistrbe];
    
    [view addAction:cancel];
    
    [self presentViewController:view animated:YES completion:nil];
    

    }

提交回复
热议问题