一、UIAlertView、 UIActionSheet都是ios系统自带的弹出式对话框,当UIAlertView或UIActionSheet弹出来时用户无法与应用界面中的其它控件交互,UIAlertView与AUIctionSheet最大的区别在于UIAlertView是表现为显示在屏幕中央的弹出式警告框,而 ActionSheet表现为显示在屏幕底部的按钮列表。

1、创建UIAlertView。创建该对象时可致定改警告框的标题、消息内容、以及该警告框包含几个按钮等信息。如果程序需要监听用户点击饿警告框时那一个按钮,则需要在创建该UIAlertView时设置UIAlertViewDelegate委托对象。

2、调用UIAlertView显示。

3、如果需要监听用户点击了警告狂的那个按钮,则需为UIAlertViewDelegate协议中的方法。

二、UIActionSheet

UIActionSheet表现为显示在底部的按钮列表,用户通过单击某个按钮来表明自己的态度。默认情况下UIActionSheet只支持一个标题和多个按钮,UIActionSheet会有两个固定的按钮和多个其它按钮。

1、其创建与UIAlertView基本一致

三、具体代码如下:(包含相关的属性)

UIAlertView:警告框、窗口
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"提示内容"delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:@"取消",@"按钮1",@"按钮2", nil];//alert创建   
    alert.title = @"标题";//设置标题
    alert.message = @"消息提示";//设置内容
   
    [alert show];
    //[alert dismissWithClickedButtonIndex:2 animated:YES];//消失alert
//触发事件
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSLog(@"%ld",(long)buttonIndex);
}
 
ActionSheet:选择器型态
添加 UIButton
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = [UIColor grayColor];
    btn.frame = CGRectMake(10, 20, 80, 80);
        [btn addTarget:self action:@selector(showAlert) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
 
    添加 UITextField
    UITextField *sexField = [[UITextField alloc] initWithFrame:CGRectMake(10, 120, 200, 30)];
    sexField.borderStyle = UITextBorderStyleRoundedRect;
    sexField.delegate = self;//添加代理
    sexField.tag = 1;
    [self.view addSubview:sexField];
//触发事件
-(void)textFieldDidBeginEditing:(UITextField *)textField{
    if (textField.tag == 1) {
       // [self showAlert];
        UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"男",@"女", nil];
        action.tag = 3;
        [action showInView:self.view];

[textField resignFirstResponder];
    }
}

-(void)showAlert{
    UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"建行",@"农行", nil];
    action.tag = 4;
    [action showInView:self.view];

}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSLog(@"=====%zi",buttonIndex);
    NSLog(@"---->%@",[actionSheet buttonTitleAtIndex:buttonIndex]);
   
    if (actionSheet.tag == 3) {
        UITextField  *field = (UITextField *)[self.view  viewWithTag:1];
        field.text = [actionSheet buttonTitleAtIndex:buttonIndex];
    }

}
 

UIAlertView、 UIActionSheet的更多相关文章

  1. UIAlertView、UIActionSheet兼容iOS8

    链接地址:http://blog.csdn.net/nextstudio/article/details/39959895?utm_source=tuicool 1.前言 iOS8新增了UIAlert ...

  2. iOS - 提示信息 - UIAlertView、UIActionSheet、UIAlertController的实际应用

    1.UIAlertView(屏幕中央弹出框)(不需要服从代理) UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@" ...

  3. iOS改变UIAlertView、UIActionSheet、UIAlertController系统字体颜色

    废话不多说,直接上代码,效果是最好的说服力 1.改变UIAlertView字体颜色 [UIView appearance].tintColor = [UIColor greenColor]; 个人还是 ...

  4. UIAlertView 与 UIActionSheet (提示用户)的使用方法

    UIAlertView 提示用户  帮助用户选择框 //    UIAlertView *alterView = [[UIAlertView alloc] initWithTitle:@"警 ...

  5. iOS 8 中 UIAlertView 和 UIActionSheet 河里去了?

    iOS 8 中 UIAlertView 和 UIActionSheet 河里去了? 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商 ...

  6. iOS:简单使用UIAlertVIew和UIActionSheet

    做iOS开发的同学想必都用过UIAlertVIew或者UIActionSheet.UIAlertVIew 可以弹出一个出现在屏幕中间的提示视图,给用户展示信息,并让用户自己选择操作,UIActionS ...

  7. iOS开发——UI篇Swift篇&UIAlertView/UIActionSheet

    UIAlertView/UIActionSheet UIAlertView //一个按钮的提醒 @IBAction func oneButtonAler() { //创建单一按钮提醒视图 let on ...

  8. 用block将UIAlertView与UIActionSheet统一起来

    用block将UIAlertView与UIActionSheet统一起来 效果 1. 将代理方法的实例对象方法转换成了类方法使用 2. 要注意单例block不要长期持有,用完就释放掉 源码 https ...

  9. iOS8以后UIAlertView和UIActionSheet两种alert页面都将通过UIAlertController来创建

    1. Important: UIAlertView is deprecated in iOS 8. (Note that UIAlertViewDelegate is also deprecated. ...

随机推荐

  1. JS中插入节点的方法appendChild和insertBefore的应用

    1.appendChild() 方法:可以向节点的子节点列表的末尾添加新的子节点.比如:appendChild(newchild)括号里可以是创建的标签var newchild = document. ...

  2. 洛谷P3367 【模板】并查集

    P3367 [模板]并查集 293通过 551提交 题目提供者HansBug 标签 难度普及- 提交  讨论  题解 最新讨论 不知道哪错了 为啥通不过最后三个节点 题解 不懂为什么MLE 最后一个数 ...

  3. Spring day02笔记

    spring day01回顾 编写流程(基于xml) 1.导入jar包:4+1 --> beans/core/context/expression | commons-logging 2.编写目 ...

  4. 内省(Introspector)

    内省(Introspector) 是Java 语言对 JavaBean 类属性.事件的一种缺省处理方法 目的:主要用于传递数据信息,这种类中的方法主要用于访问私有的字段(且方法名符合某种命名规则) p ...

  5. XidianOJ 1182 Chinese Paladin – Qi’s troubles

    题目描述 As we all know, Xiahou Jinxuan (Chinese Paladin 5 Prequel's protagonist) and Yue Jinzhao (Chine ...

  6. dubbo 使用总结

    第一步: 安装注册中心Register,这里选择 zookeeper 1.zookeeper下载url:http://zookeeper.apache.org; 2.下载解压完后如下: 3.将zoo_ ...

  7. 各种音视频编解码学习详解 h264 ,mpeg4 ,aac 等所有音视频格式

    编解码学习笔记(一):基本概念 媒体业务是网络的主要业务之间.尤其移动互联网业务的兴起,在运营商和应用开发商中,媒体业务份量极重,其中媒体的编解码服务涉及需求分析.应用开发.释放 license收费等 ...

  8. 未能加载文件或程序集Microsoft.ReportViewer.WebForms, Version=10.0.0.0

    解决方案如下ASP.NET项目使用VS2010开发,部署到windows 2008环境中,出现未能加载文件或程序集“Microsoft.ReportViewer.WebForms, Version=1 ...

  9. C# 关于时间

    1.2016/7/8 00:10:10 转换成 2016-07-08T 00:10:10 在用VB动态调用WevService的时候,传入的时间格式为2016/7/8 00:10:10,导致调用出错, ...

  10. Oracle基础知识笔记

    1.打开oracle相关服务 2.创建Oracle用户 create user 用户名 identified by 密码;(需要dba角色创建) 3.权限管理 (1)添加权限 grant  权限.角色 ...