首页 > 其他 > 详细

UIAlertController类--sheet上拉菜单1(基本的)

时间:2015-11-18 16:26:06      阅读:320      评论:0      收藏:0      [点我收藏+]

一、效果

技术分享

 

二、代码实现

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

{

    [self sheetTest1];

}

 

/**

 注意:不能在上拉菜单中添加文本框

    如果强行添加了文本框,会报运行时错误:

    reason: ‘Text fields can only be added to an alert controller of style UIAlertControllerStyleAlert‘

 */

/**

 *  底部上拉菜单

 */

- (void)sheetTest1

{

    /**

     当需要给用户展示一系列选择的时候,上拉菜单就能够派上大用场了,上拉菜单的展示形式和设备大小有关。

     1.在iPhone上(紧缩宽度),上拉菜单从屏幕底部升起

     2.在iPad上(常规宽度),上拉菜单以弹出框的形式展现

     创建上拉菜单的方式和创建对话框的方式非常类似,唯一的区别是它们的形式

     */

    

    /**

     注意:“取消”按钮,总是在上拉菜单的底部

     《iOS 用户界面指南》要求所有的“毁坏”样式按钮都必须排名第一,并且是红色的。

     */

    

    //1.创建视图控制器

    UIAlertController *alertController = [UIAlertController

                                          alertControllerWithTitle:@"保存或删除数据"

                                          message:@"删除数据将不可恢复"

                                          preferredStyle:UIAlertControllerStyleActionSheet];

    

    //2.添加按钮

    UIAlertAction *cancelAction = [UIAlertAction

                                   actionWithTitle:@"取消"

                                   style:UIAlertActionStyleCancel

                                   handler:nil];

    UIAlertAction *deleteAction = [UIAlertAction

                                   actionWithTitle:@"删除"

                                   style:UIAlertActionStyleDestructive

                                   handler:nil];

    UIAlertAction *archiveAction = [UIAlertAction

                                    actionWithTitle:@"保存"

                                    style:UIAlertActionStyleDefault

                                    handler:nil];

    

    //3.添加按钮到视图控制器

    [alertController addAction:cancelAction];

    [alertController addAction:deleteAction];

    [alertController addAction:archiveAction];

    

    //4.展示视图控制器

    [self presentViewController:alertController animated:YES completion:nil];

    

}

UIAlertController类--sheet上拉菜单1(基本的)

原文:http://www.cnblogs.com/M-Y-P/p/4972584.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!