我想要创建这种菜单,当然还有其他的菜单按钮。是否有默认的视图控制器可以代表它,或者我需要获取图片并自己创建呢。
我想要创建这种菜单,当然还有其他的菜单按钮。是否有默认的视图控制器可以代表它,或者我需要获取图片并自己创建呢。
您需要使用 UIActionSheet
。
首先,您需要在您的 ViewController.h 文件中添加 UIActionSheetDelegate
。
然后,您可以使用以下代码引用 actionsheet:
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];
那么你必须处理每个调用。
- (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;
}
}
这已经被弃用于iOS 8.x https://developer.apple.com/documentation/uikit/uialertcontroller#//apple_ref/occ/cl/UIAlertController
UIActionSheet
并且提供了好的答案,所以我要给你个“+1”。 - rmaddyTake a look at the UIActionSheet documentation.
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];
这被称为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];
实现UISctionSheetDelegate以响应按钮操作。
查看此教程以获取更多信息:http://mobile.tutsplus.com/tutorials/iphone/uiactionsheet_uiactionsheetdelegate(代码来自此教程)