如何使用iOS上的按钮创建警报,从底部滑动?

时间:2016-03-20 16:39:56

标签: ios user-interface

如何在iOS上创建像Instagram取消关注警报(两个按钮,图像和消息)的提醒?有没有现成的组件或我应该从头开发它? 这是一个截图:

enter image description here

2 个答案:

答案 0 :(得分:7)

有一个实现(UIAlertController),但没有图像。

这是一个有效的例子:

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];

您可以在这篇文章中找到有关如何将图像添加到UIAlertController的更多信息:

Add Image to UIAlertAction in UIAlertController

答案 1 :(得分:0)

Swift 4版本

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)