2015-04-21 14 views
31

Quando si utilizza un UIAlertController, se si desidera presentare un UIActionSheet con un titolo vuoto e un messaggio vuoto, rimane il frame per il posizionamento previsto del titolo e/o del messaggio.Come nascondere la struttura del titolo/messaggio in un UIAlertController?

Come faccio a cambiare questo in modo che vi presento solo ActionSheet che recita:

Impostazioni
Esci
Annulla ?

Grazie!

UIAlertController example

risposta

76

Quando creo un UIAlertController con questo codice non ho la spaziatura titolo.

[UIAlertController alertControllerWithTitle:nil 
            message:nil 
          preferredStyle:UIAlertControllerStyleActionSheet]; 

Stai passando in nil per il titolo e il messaggio o stringhe vuote?

+1

Era piuttosto semplice. E questo ha risposto alla mia domanda. Grazie – vlin

0

UIAlertController * regolatore = [UIAlertController alertControllerWithTitle: @ "" un messaggio: @ "" preferredStyle: UIAlertControllerStyleAlert]; // controllo stile

UIAlertAction *first = [UIAlertAction actionWithTitle: @"Login with Facebook" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) 
{ 
    //write to perform action 

}]; 


[controller addAction: first]; 



UIAlertAction *second = [UIAlertAction actionWithTitle: @"Guest User" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) 

{// scrivere per eseguire l'operazione

}]; 

[controller addAction:second]; 


UIAlertAction *third=[UIAlertAction actionWithTitle:@"Registered User" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) 


{ 
    //write to perform action 

}]; 

[controller addAction:third]; 

[self presentViewController: controller animated: YES completion: nil]; 
3

Se si desidera modificare il tempo di esecuzione in base a un determinato caso, scrivere:

actionController.title = nil
actionController.message = nil

0

a Swift 2.2, è possibile utilizzare il codice qui sotto e ho anche cambiato il colore del pulsante di azione signout

 let actionSheet: UIAlertController = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet) 

    self.presentViewController(actionSheet, animated: true, completion: nil) 

    let settingsActionButton: UIAlertAction = UIAlertAction(title: "Settings", style: .Cancel) { action -> Void in 
     print("Settings Tapped") 
    } 

    reportActionSheet.addAction(settingsActionButton) 

    let signOutActionButton: UIAlertAction = UIAlertAction(title: "Signout", style: .Default) 
    { action -> Void in 
     //Clear All Method 
     print("Signout Tapped") 

    } 

    signOutActionButton.setValue(UIColor.redColor(), forKey: "titleTextColor") 

    actionSheet.addAction(signOutActionButton) 

    let cancelActionButton: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in 
     print("Cancel Tapped") 
    } 

    reportActionSheet.addAction(cancelActionButton) 
0

Aggiornamento Swift 4:

let alert = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.actionSheet) 

solo bisogno di passare niente a titolo e parametri del messaggio.

Grazie

Problemi correlati