5

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:

enter image description here

Semyon Tikhonenko
  • 3,872
  • 6
  • 36
  • 61

2 Answers2

9

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

Community
  • 1
  • 1
marco.marinangeli
  • 899
  • 14
  • 29
6

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)