Creating iPhone Pop-up Menu Similar to Mail App Menu

后端 未结 7 1590
野趣味
野趣味 2020-12-01 05:52

I\'d like to create a pop-up menu similar to the one found in the mail app when you want to reply to a message. I\'ve seen this in more than one application so I wasn\'t su

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 06:21

    You need to use a UIActionSheet.

    First you need to add UIActionSheetDelegate to your ViewController .h file.

    Then you can reference an actionsheet with:

      UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Select Sharing option:" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:
                            @"Share on Facebook",
                            @"Share on Twitter",
                            @"Share via E-mail",
                            @"Save to Camera Roll",
                            @"Rate this App",
                            nil];
       popup.tag = 1;
      [popup showInView:self.view];
    

    Then you have to handle each of the calls.

    - (void)actionSheet:(UIActionSheet *)popup clickedButtonAtIndex:(NSInteger)buttonIndex {
    
      switch (popup.tag) {
        case 1: {
            switch (buttonIndex) {
                case 0:
                    [self FBShare];
                    break;
                case 1:
                    [self TwitterShare];
                    break;
                case 2:
                    [self emailContent];
                    break;
                case 3:
                    [self saveContent];
                    break;
                case 4:
                    [self rateAppYes];
                    break;
                default:
                    break;
            }
            break;
        }
        default:
            break;
     }
    }
    

    This has been deprecated as of iOS 8.x.

    https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UIAlertController_class/index.html

提交回复
热议问题