zoukankan      html  css  js  c++  java
  • 警告视图及操作表单在xcode7.0中的使用

    警告视图(alert)及操作表单(action sheet)都用于向用户提供反馈。(模态视图)

    操作表单:要求用户在两个以上选项之间做出选择。操作表单从屏幕底部出现,显示一系列按钮供用户选择。用户必须点击其中一个按钮之后才能继续使用应用程序。操作表单通常用于向用户确认有潜在危险的或者无法撤销的操作,比如删除对象。

    警告视图:以圆角矩形的形式出现在屏幕中央。与操作表单类似,警告视图也要求用户必须作出一个回应,然后才能继续使用应用程序。警告视图通常用于通知用户发生了一些重要的或者不寻常的事情。与操作表单不同,警告视图可以只显示一个按钮,但是如果需要接受多个回应的话,也允许显示多个。

    使用方式如下代码:

        NSString *title = @"A short Title is Best";
        NSString *message = @"A message should be a short, complete sentence";
        NSString *cancelButtonTitle = @"Cancel";
        NSString *otherButtonTitle = @"OK";
        
        //警告框
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
        
        //添加输入框(警告框才具备)
        [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
            // 可以对textField进行定制,如修改背景色
            textField.backgroundColor = [UIColor orangeColor];
        }];
        
    //    //操作表单
    //    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        
        
        //create the actions
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"Cancel action occured.");
        }];
        
        UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"Other action occured.");
        }];
        
        [alertController addAction:cancelAction];
        [alertController addAction:otherAction];
        
        //显示
        [self presentViewController:alertController animated:YES completion:nil];
  • 相关阅读:
    【Quartz】1、Quartz使用说明
    【Servlet】1、Servlet监听器及相关接口
    【IDEA&&Eclipse】5、IntelliJ IDEA常见配置
    Chris Richardson微服务实战系列
    Traefik Kubernetes 初试
    用友iuap云运维平台支持基于K8s的微服务架构
    DCOS中监控和弹性伸缩方案经验
    使用微服务架构改造遗留系统
    kubernetes中port、target port、node port的对比分析,以及kube-proxy代理
    基于prometheus监控k8s集群
  • 原文地址:https://www.cnblogs.com/smile-smile/p/5358164.html
Copyright © 2011-2022 走看看