Vorrei creare questo tipo di menu, ovviamente con altri pulsanti di menu. Esiste un viewcontroller predefinito che lo rappresenta, oppure devo ottenere immagini e crearlo da solo.Creazione di UIActionSheet
risposta
Date un'occhiata alla documentazione di UIActionSheet.
NSString *actionSheetTitle = @"Action Sheet Demo"; //Action Sheet Title
NSString *destructiveTitle = @"Destructive Button"; //Action Sheet Button Titles
NSString *other1 = @"Other Button 1";
NSString *other2 = @"Other Button 2";
NSString *other3 = @"Other Button 3";
NSString *cancelTitle = @"Cancel Button";
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:actionSheetTitle
delegate:self
cancelButtonTitle:cancelTitle
destructiveButtonTitle:destructiveTitle
otherButtonTitles:other1, other2, other3, nil];
[actionSheet showInView:self.view];
Quello che stai cercando è chiamato un foglio di azioni. Per saperne di più qui http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIActionSheet_Class/Reference/Reference.html
È necessario utilizzare un UIActionSheet
.
Per prima cosa è necessario aggiungere UIActionSheetDelegate
al file ViewController.h.
Quindi è possibile fare riferimento a un actionsheet con:
UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Select Sharing option:" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:
@"Share on Facebook",
@"Share on Twitter",
@"Share via E-mail",
@"Save to Camera Roll",
@"Rate this App",
nil];
popup.tag = 1;
[popup showInView:self.view];
poi si deve gestire ciascuna delle chiamate.
- (void)actionSheet:(UIActionSheet *)popup clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (popup.tag) {
case 1: {
switch (buttonIndex) {
case 0:
[self FBShare];
break;
case 1:
[self TwitterShare];
break;
case 2:
[self emailContent];
break;
case 3:
[self saveContent];
break;
case 4:
[self rateAppYes];
break;
default:
break;
}
break;
}
default:
break;
}
}
Questo è stato deprecato per iOS 8.x https://developer.apple.com/documentation/uikit/uialertcontroller#//apple_ref/occ/cl/UIAlertController
+! per essere l'unico a chiamarlo "UIActionSheet" (oltre a fornire una buona risposta). – rmaddy
Stavo letteralmente lavorando alla mia app mentre vedevo la domanda! Viene dal mio codice verbatim;) – ApolloSoftware
funziona anche senza aggiungere UIActionSheetDelegate .. Voglio sapere come ... – Nepster
Si chiama un UIActionSheet: Si crea uno in questo modo:
NSString *actionSheetTitle = @"Action Sheet Demo"; //Action Sheet Title
NSString *destructiveTitle = @"Destructive Button"; //Action Sheet Button Titles
NSString *other1 = @"Other Button 1";
NSString *other2 = @"Other Button 2";
NSString *other3 = @"Other Button 3";
NSString *cancelTitle = @"Cancel Button";
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:actionSheetTitle
delegate:self
cancelButtonTitle:cancelTitle
destructiveButtonTitle:destructiveTitle
otherButtonTitles:other1, other2, other3, nil];
[actionSheet showInView:self.view];
Implementare l'UISctionSheetDelegate di rispondere all'azione pulsante.
Date un'occhiata a questo tutorial per maggiori informazioni: http://mobile.tutsplus.com/tutorials/iphone/uiactionsheet_uiactionsheetdelegate (Codice è da questo tutorial)
Il titolo e la popolarità di questa domanda è molto meglio del duplicato. Sarebbe bello riaprire questa domanda in modo da poter aggiungere risposte aggiornate. – Suragch
Vota per riaprire per favore. – Stunner
@ Suragch hai ragione. è più utile e comprensibile di altri link –