Add Image to UIAlertAction in UIAlertController

2019-01-03 05:37发布

I have seen a couple screen shots of a UIAlertControllers with an image on the left of the row but I do not seen it in the documentation. An example visual is http://imgur.com/SISBvjB Here is the code that I have for my controller right now:

UIAlertController * view =   [UIAlertController
                                 alertControllerWithTitle:@"My Title"
                                 message:@"Select you Choice"
                                 preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction* ok = [UIAlertAction
                         actionWithTitle:@"OK"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                          }];
    [view addAction:ok];
    [self presentViewController:view animated:YES completion:nil];

7条回答
女痞
2楼-- · 2019-01-03 06:03
UIAlertController * view=   [UIAlertController
                             alertControllerWithTitle:@"Staus ! "
                             message:@"Select your current status"
                             preferredStyle:UIAlertControllerStyleActionSheet];


UIAlertAction* online = [UIAlertAction
                     actionWithTitle:@"Online"
                     style:UIAlertActionStyleDefault
                     handler:^(UIAlertAction * action)
                     {
                         //Do some thing here
                         [view dismissViewControllerAnimated:YES completion:nil];

                     }];
UIAlertAction* offline = [UIAlertAction
                         actionWithTitle:@"Offline"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                             [view dismissViewControllerAnimated:YES completion:nil];

                         }];
UIAlertAction* doNotDistrbe = [UIAlertAction
                         actionWithTitle:@"Do not disturb"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                             [view dismissViewControllerAnimated:YES completion:nil];

                         }];
UIAlertAction* away = [UIAlertAction
                               actionWithTitle:@"Do not disturb"
                               style:UIAlertActionStyleDestructive
                               handler:^(UIAlertAction * action)
                               {
                                   [view dismissViewControllerAnimated:YES completion:nil];

                               }];

[online setValue:[[UIImage imageNamed:@"online.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"];
[offline setValue:[[UIImage imageNamed:@"offline.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"];
[doNotDistrbe setValue:[[UIImage imageNamed:@"DND.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"];
[away setValue:[[UIImage imageNamed:@"away.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"];





[view addAction:online];
[view addAction:away];
[view addAction:offline];
[view addAction:doNotDistrbe];
[self presentViewController:view animated:YES completion:nil];
查看更多
登录 后发表回答