Creating iPhone Pop-up Menu Similar to Mail App Menu

后端 未结 7 1588
野趣味
野趣味 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:15

    This is how you'd do it in Objective-C on iOS 8+:

        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Directions"
                                                                               message:@"Select mode of transportation:"
                                                                        preferredStyle:UIAlertControllerStyleActionSheet];
        UIAlertAction *drivingAction = [UIAlertAction actionWithTitle:@"Driving" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            // this block runs when the driving option is selected
        }];
        UIAlertAction *walkingAction = [UIAlertAction actionWithTitle:@"Walking" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            // this block runs when the walking option is selected
        }];
        UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
        [alert addAction:drivingAction];
        [alert addAction:walkingAction];
        [alert addAction:defaultAction];
        [self presentViewController:alert animated:YES completion:nil];
    

提交回复
热议问题