简体   繁体   中英

How to create alert, sliding from bottom with buttons on iOS?

How to create an alert like Instagram unfollow alert(two buttons, image and message) on iOS? Is there any ready component or should I develop it from scratch? Here is a screenshot:

在此输入图像描述

There is an implementation (UIAlertController), but without the image.

Here's a working example:

UIAlertController* deleteAlert = [UIAlertController alertControllerWithTitle:@"Unfollow?"
                                                                     message:
                                                              preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction* unfollowAction = [UIAlertAction actionWithTitle:@"Unfollow" style:UIAlertActionStyleDestructive
                                                     handler:^(UIAlertAction * action) {
                                                         //Code to unfollow
                                                     }];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel
                                                     handler:^(UIAlertAction * action) {

                                                     }];

[deleteAlert addAction:unfollowAction];
[deleteAlert addAction:cancelAction];
[self presentViewController:deleteAlert animated:YES completion:nil];

You can find more informations on how to add an image to a UIAlertController in this post:

Add Image to UIAlertAction in UIAlertController

Swift 4 version

let deleteAlert = UIAlertController(title: "Unfollow", message: "", preferredStyle: UIAlertController.Style.actionSheet)

    let unfollowAction = UIAlertAction(title: "Unfollow", style: .destructive) { (action: UIAlertAction) in
        // Code to unfollow
    }

    let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)

    deleteAlert.addAction(unfollowAction)
    deleteAlert.addAction(cancelAction)
    self.present(deleteAlert, animated: true, completion: nil)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM