2015-05-20 4 views
2

enter image description hereIOS меню модальных наложений

мне было интересно, есть ли встроенное зрение в XCode для отображения всплывающего меню, как это для IOS приложений? Что-то вроде предупреждения, за исключением всего лишь набора вертикально-уложенных кнопок?

EDIT:

Я знал о UIAlertController, только не то, что его кнопки расположены вертикально после того, как вы добавите более чем в 2 раза, что стиль я шел. Просто очистите, так как просто кнопки задают заголовок и сообщение ничто.

+0

Если один из ответов помог вам, вы должны принять его, чтобы пометить вопрос ответил :) –

ответ

2

Да. Это называется UIAlertController

+0

Хорошо, я тупой. Не реализовывали действия (кнопки) стек вертикально, когда вы добавляете более двух из них. –

2

Вы можете использовать UIAlertController

UIAlertController *alertController = [UIAlertController 
             alertControllerWithTitle:@"" 
             message:@"" preferredStyle:UIAlertControllerStyleAlert]; 

UIAlertAction *searchAction = [UIAlertAction 
          actionWithTitle:NSLocalizedString(@"Search for an image", @"search action") 
          style:UIAlertActionStyleDefault 
          handler:^(UIAlertAction *action) 
          { 
           //Add your code         
          }]; 

UIAlertAction *choosePhotoAction = [UIAlertAction 
          actionWithTitle:NSLocalizedString(@"Choose Photo", @"choosePhoto action") 
          style:UIAlertActionStyleDefault 
          handler:^(UIAlertAction *action) 
          { 
           //Your code 
          }]; 

UIAlertAction *takePhotoAction = [UIAlertAction 
          actionWithTitle:NSLocalizedString(@"Take Photo", @"takePhoto action") 
          style:UIAlertActionStyleDefault 
          handler:^(UIAlertAction *action) 
          { 
           //Your code 
          }]; 

UIAlertAction *cancelAction = [UIAlertAction 
            actionWithTitle:NSLocalizedString(@"Cancel", @"cancel action") 
            style:UIAlertActionStyleDefault 
            handler:^(UIAlertAction *action) 
            { 
             NSLog(@"cancel action"); 

            }]; 

[alertController addAction:searchAction]; 
[alertController addAction:choosePhotoAction]; 
[alertController addAction:takePhotoAction]; 
[alertController addAction:cancelAction]; 
[self presentViewController:alertController animated:YES completion:nil]; 
2

Да, UIAlertController предусмотрен для установки других элементов управления на оповещение зрения.

UIAlertController * alert= [UIAlertController 
           alertControllerWithTitle:@"My Title" 
           message:@"Enter User Credentials" 
           preferredStyle:UIAlertControllerStyleAlert]; 

UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault 
              handler:^(UIAlertAction * action) { 
               //Do Some action here 

              }]; 
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault 
               handler:^(UIAlertAction * action) { 
                [alert dismissViewControllerAnimated:YES completion:nil]; 
               }]; 

[alert addAction:ok]; 
[alert addAction:cancel]; 

[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { 
    textField.placeholder = @"Username"; 
}]; 
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { 
    textField.placeholder = @"Password"; 
    textField.secureTextEntry = YES; 
}]; 

[self presentViewController:alert animated:YES completion:nil]; 
1

@Richa решение, но в быстрой версии

let alertController = UIAlertController(title: "", message: "", preferredStyle: .alert) 
    let searchAction = UIAlertAction(title: NSLocalizedString("Search for an image", comment: "search action"), style: .default, handler: {(action: UIAlertAction) -> Void in 
     //Add your code 
    }) 
    let choosePhotoAction = UIAlertAction(title: NSLocalizedString("Choose Photo", comment: "choosePhoto action"), style: .default, handler: {(action: UIAlertAction) -> Void in 
     //Your code 
    }) 
    let takePhotoAction = UIAlertAction(title: NSLocalizedString("Take Photo", comment: "takePhoto action"), style: .default, handler: {(action: UIAlertAction) -> Void in 
     //Your code 
    }) 
    let cancelAction = UIAlertAction(title: NSLocalizedString("Cancel", comment: "cancel action"), style: .default, handler: {(action: UIAlertAction) -> Void in 
     print("cancel action") 
    }) 
    alertController.addAction(searchAction) 
    alertController.addAction(choosePhotoAction) 
    alertController.addAction(takePhotoAction) 
    alertController.addAction(cancelAction) 
    self.present(alertController, animated: true, completion: nil) 
Смежные вопросы