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 b开发者_高级运维uttons)?
Thanks in advance!
That's UIActionSheet class from standard UIKit framework
Easy example from Apple's documentation of UIActionSheet
extended a bit by me to fire call action.
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]
精彩评论