Ios 创建弹出按钮界面
在苹果的股票“信息”应用程序中,点击相机按钮会显示弹出按钮,允许用户拍摄照片/视频或选择现有的照片/视频。我将如何实现同样的按钮设计?iPhone和iPad的操作程序都一样吗?它被称为Ios 创建弹出按钮界面,ios,objective-c,cocoa-touch,button,Ios,Objective C,Cocoa Touch,Button,在苹果的股票“信息”应用程序中,点击相机按钮会显示弹出按钮,允许用户拍摄照片/视频或选择现有的照片/视频。我将如何实现同样的按钮设计?iPhone和iPad的操作程序都一样吗?它被称为UIActionSheet。你是这样用的 UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"Foo" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
UIActionSheet
。你是这样用的
UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"Foo" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"foo1", @"foo2", nil];
[action showInView:self.view];
(将foos更改为which)。要检测单击的按钮,请执行UIActionSheetDelegate
的actionSheet:ClickedButtonIndex:
delegate方法。例如:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([title isEqualToString:@"foo1"]) {
// do stuff...
}
}
是的,这在iPhone和iPad上都有效(正如@bobnoble所指出的,iPad版本使用的是popover视图,而不是动作表,但动作表在两者上都有效)。在iPad上,在popover中显示
UIActionSheet
,与在iPad版本中显示的消息相同。在iPhone上,您可能需要添加一个“取消”按钮。