Samui
Samui

Reputation: 1384

How can I achieve a similar menu view? [iOS]

Is there a way to achieve this menu easily with the sdk or do I have to make it manually (combining an overlay view and other view with the buttons)?

enter image description here

Thanks in advance!

Upvotes: 1

Views: 297

Answers (2)

andilabs
andilabs

Reputation: 23282

Easy example from Apple's documentation of UIActionSheet extended a bit by me to fire call action.

enter image description here Delcare in the global scope of the ViewController: UIActionSheet * actionSheet; and UIView * yourView;

Int the viewDidLoad:

actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                             delegate:self
                             cancelButtonTitle:@"Cancel"
                             destructiveButtonTitle:@"Delete Note"
                             otherButtonTitles:@"Call",@"Add a Contact",nil];

[yourView = self.view]

To fire the menu by some declared button with IBAction you will need:

-(IBAction)viewMapButton:(id) sender
{
    [actionSheet showInView:yourView];

}

To take appropriate action depending on user choice declare following method and check what [actionSheet buttonTitleAtIndex:buttonIndex] was equal to:

- (void)actionSheet:(UIActionSheet *)actionSheet
        clickedButtonAtIndex:(NSInteger)buttonIndex
        {
        NSString * what_action = [actionSheet buttonTitleAtIndex:buttonIndex];
        NSLog(@"The %@ button was tapped.", what_action);
             if ([what_action isEqualToString:@"Call"])
                 {
                 NSString *phoneNumber = [[NSString alloc] 
                        initWithString:@"telprompt:1234567890"];
                 [[UIApplication sharedApplication] 
                        openURL:[NSURL URLWithString:phoneNumber]];
                 }
}

[NOTE: Firing of call does not work on iOS Simulator]

Upvotes: 0

Vladimir
Vladimir

Reputation: 170829

That's UIActionSheet class from standard UIKit framework

Upvotes: 4

Related Questions