三、iOS8之后的弹窗指示器

在用户使用App进行一些危险性操作时,使用对话框的形式提示用户能起到很为用户着想的作用。经常使用的对话框有以下两种:UIActionSheet 和  UIAlertView。但在ios8之后 UIActionSheet 和  UIAlertView都定义为过时了,官方文档解释:

UIActionSheet is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleActionSheet instead

 

以下就是常用两种对话框的基本使用:

 

 // 第一种方式

    // 创建弹框指示器

    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"请确定要取消吗?" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:nil, nil];

    // 弹框提示

    [sheet showInView:nil];

  // 使用 UIActionSheet的代理方法进行相关操作

#pragma mark - actionSheet的代理方法

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;

{

    if (buttonIndex == 0) {// 点击确定按钮

    // 写上需要进行相关操作的代码

}

 

    // 第二种方式

    // 创建对话框

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"亲,确定要注销吗?" preferredStyle:UIAlertControllerStyleActionSheet];

    // 创建取消按钮

    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

        // 相关操作

    }];

    // 创建确定按钮

    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {

        // 回调方法

        [self.navigationController popViewControllerAnimated:YES];

    }];

    // 添加按钮到对话框

    [alert addAction:cancelAction];

    [alert addAction:sureAction];

    // 显示对话框

    [self presentViewController:alert animated:YES completion:^{

     // 完成显示后的相关操作

    }];

 

     

转载于:https://www.cnblogs.com/muqizi/p/4617455.html

创建一个iOS手机端弹窗生成器涉及到iOS应用开发的知识,主要使用Swift或Objective-C语言进行编程,并且需要使用Xcode作为开发环境。以下是创建一个基础的弹窗生成器的基本步骤: 1. 创建一个新的iOS项目:使用Xcode创建一个新的iOS项目,选择需要的模板,比如Single View App。 2. 设计UI界面:在项目中使用Storyboard或Xib文件来设计用户界面。如果你想要弹窗,通常会使用UIAlertController来创建。 3. 实现弹窗功能: - 在Swift中,你可以使用UIAlertController来创建一个弹窗,并且可以通过配置它的一些属性来实现不同的效果。 - 创建UIAlertController实例,指定弹窗的标题、消息和样式(.alert或.actionSheet)。 - 向UIAlertController添加一个或多个动作(UIActionSheetButton或UIAlertAction),这些动作定义了用户点击弹窗上按钮时的响应。 - 最后,通过`present`方法展示弹窗。 下面是一个简单的Swift代码示例,展示了如何在iOS应用中生成一个弹窗: ```swift // 在视图控制器中展示弹窗 func showAlertController() { let alertController = UIAlertController(title: "提示", message: "这是一个弹窗示例", preferredStyle: .alert) // 添加一个动作 let cancelAction = UIAlertAction(title: "取消", style: .cancel) { (action) in // 用户点击取消按钮的代码逻辑 } // 添加一个动作 let okAction = UIAlertAction(title: "确定", style: .default) { (action) in // 用户点击确定按钮的代码逻辑 } // 将动作添加到UIAlertController alertController.addAction(cancelAction) alertController.addAction(okAction) // 展示弹窗 self.present(alertController, animated: true, completion: nil) } ``` 4. 在需要的地方调用弹窗方法:在适当的地方(比如用户触发某个事件时)调用上述创建弹窗的方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值