Creating a pop up button interface

坚强是说给别人听的谎言 提交于 2019-12-25 16:43:53

问题


In Apple's stock 'Messages' app, tapping the camera button reveals popup buttons allowing the user to take a photo/video or choose an existing one. How would I implemented this same button design? Is the procedure the same for both iPhone & iPad?


回答1:


It's called a UIActionSheet. You use it like this

UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"Foo" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"foo1", @"foo2", nil];
[action showInView:self.view];

(change the foos to whatever). To detect what button was clicked, implement the UIActionSheetDelegate's actionSheet:clickedButtonAtIndex: delegate method. For example:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];
    if ([title isEqualToString:@"foo1"]) {
        // do stuff...
    }
}

And yes, this works on both the iPhone and iPad (as @bobnoble pointed out, the iPad version uses a popover view, not an action sheet, but action sheets work on both).



来源:https://stackoverflow.com/questions/17374212/creating-a-pop-up-button-interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!