我想创建这种菜单,当然还有其他菜单按钮。有没有默认的视图控制器表示它,或者我必须获取图像并自己创建它。
发布于 2013-06-21 04:34:44
您需要使用UIActionSheet
。
首先,您需要将UIActionSheetDelegate
添加到ViewController.h文件中。
然后,您可以使用以下命令引用操作表:
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,此选项已弃用
发布于 2013-06-21 04:32:53
请看一下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];
发布于 2013-06-21 04:34:51
它被称为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 (代码来自本教程)
https://stackoverflow.com/questions/17223210
复制相似问题