Reputation: 1
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?
Upvotes: 0
Views: 172
Reputation: 5745
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).
Upvotes: 2