当前位置:  开发笔记 > 前端 > 正文

创建iPhone弹出菜单与Mail App Menu类似

如何解决《创建iPhone弹出菜单与MailAppMenu类似》经验,为你挑选了5个好方法。

当您想要回复邮件时,我想创建一个类似于邮件应用程序中的弹出菜单.我在多个应用程序中看到过这个,所以我不确定框架中是否有内置的东西或者那些示例代码.

UIActionSheet示例



1> Suragch..:
在Swift中创建一个操作表

代码已针对Swift 3进行了更新

在此输入图像描述

自iOS 8开始,UIAlertController结合UIAlertControllerStyle.ActionSheet使用.UIActionSheet已弃用.

以下是在上图中生成操作表的代码:

class ViewController: UIViewController {

    @IBOutlet weak var showActionSheetButton: UIButton!

    @IBAction func showActionSheetButtonTapped(sender: UIButton) {

        // Create the action sheet
        let myActionSheet = UIAlertController(title: "Color", message: "What color would you like?", preferredStyle: UIAlertController.Style.actionSheet)

        // blue action button
        let blueAction = UIAlertAction(title: "Blue", style: UIAlertAction.Style.default) { (action) in
            print("Blue action button tapped")
        }

        // red action button
        let redAction = UIAlertAction(title: "Red", style: UIAlertAction.Style.default) { (action) in
            print("Red action button tapped")
        }

        // yellow action button
        let yellowAction = UIAlertAction(title: "Yellow", style: UIAlertAction.Style.default) { (action) in
            print("Yellow action button tapped")
        }

        // cancel action button
        let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel) { (action) in
            print("Cancel action button tapped")
        }

        // add action buttons to action sheet
        myActionSheet.addAction(blueAction)
        myActionSheet.addAction(redAction)
        myActionSheet.addAction(yellowAction)
        myActionSheet.addAction(cancelAction)

        // present the action sheet
        self.present(myActionSheet, animated: true, completion: nil)
    }
}

还需要帮忙吗?观看此视频教程.这就是我学习它的方式.

Swift中的UIActionSheet示例(与名称相反,它确实使用新的UIAlertController操作表而不是UIActionSheet.)



2> Rémy..:

它是UIAlertControlleriOS 8+以及UIActionSheet早期版本的.



3> 小智..:

查看Apple网站上的UICatalog示例."警报"部分提供了如何使用UIActionSheet来完成您要执行的操作的示例.



4> Apollo SOFTW..:

您需要使用UIActionSheet.

首先,您需要将UIActionSheetDelegate添加到ViewController .h文件中.

然后,您可以引用一个动作表:

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

然后你必须处理每个电话.

- (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;
 }
}

从iOS 8.x开始,这已被弃用.

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



5> Stunner..:

这就是你在iOS 8+上使用Objective-C的方法:

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

推荐阅读
小妖694_807
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有