zoukankan      html  css  js  c++  java
  • UIAlertView笔记

    链接地址:http://www.cnblogs.com/scandy-yuan/archive/2013/03/11/2954194.html

    1. 最简单的用法

    复制代码
    UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示" 
    
                                                      message:@"这是一个简单的警告框!" 
    
                                                      delegate:nil   
    
                                                      cancelButtonTitle:@"确定" 
    
                                                      otherButtonTitles:nil];  
    
    [alert show];  
    复制代码

    2. 为UIAlertView添加多个按钮

    复制代码
    UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示" 
    
                                                      message:@"请选择一个按钮:" 
    
                                                      delegate:nil   
    
                                                      cancelButtonTitle:@"取消" 
    
                                                      otherButtonTitles:@"按钮一", 
                                                                              @"按钮二",
                                                                              @"按钮三", nil]
    [alert show];                      
    复制代码

     3. 如何判断用户点击的按钮

    UIAlertView有一个委托UIAlertViewDelegate ,继承该委托来实现点击事件

    复制代码
    头文件:
    
    @interface MyAlertViewViewController : UIViewController<UIAlertViewDelegate> {
    
    }
    
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
    
    -(IBAction) buttonPressed;
    
    @end
    
    
    源文件:
    
    -(IBAction) buttonPressed
    
    {
    
    UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示" 
    
                                                     message:@"请选择一个按钮:" 
    
                                                     delegate:self   
    
                                                     cancelButtonTitle:@"取消" 
    
                                                     otherButtonTitles:@"按钮一", @"按钮二", @"按钮三",nil];  
    
    [alert show];  
    
    }
    
     
    
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    
    {
    
    NSString* msg = [[NSString alloc] initWithFormat:@"您按下的第%d个按钮!",buttonIndex];
    
     
    
    UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"提示"
    
                                                     message:msg
    
                                                     delegate:nil
    
                                                     cancelButtonTitle:@"确定"
    
                                                     otherButtonTitles:nil];
    
     
    
    [alert show];
    
    }
    复制代码

    点击“取消”,“按钮一”,“按钮二”,“按钮三”的索引buttonIndex分别是0,1,2,3

    4.修改提示框样式

    iOS5中UIAlertView新增了一个属性alertViewStyle,它的类型是UIAlertViewStyle,是一个枚举值:

    typedef enum {
        UIAlertViewStyleDefault = 0,
        UIAlertViewStyleSecureTextInput,
        UIAlertViewStylePlainTextInput,
        UIAlertViewStyleLoginAndPasswordInput
    } UIAlertViewStyle;

    alertViewStyle属性默认是UIAlertViewStyleDefault。我们可以把它设置为UIAlertViewStylePlainTextInput,那么AlertView就显示为这样:

    UIAlertViewStyleSecureTextInput显示为:

    UIAlertViewStyleLoginAndPasswordInput为:

    当然我们也可以通过创建UITextField来关联这里的输入框并设置键盘响应的样式

    复制代码
    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"CD-KEY" 
    
                                                     message:@"please enter cd-key:" 
    
                                                     delegate:self   
    
                                                     cancelButtonTitle:@"Cancel" 
    
                                                     otherButtonTitles:@"Ok",nil];  
    [alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
    
    UITextField * text1 = [alert textFieldAtIndex:0];
    
    UITextField * text2 = [alert textFieldAtIndex:1];
    
    text1.keyboardType = UIKeyboardTypeNumberPad;
    
    text2.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    
    [alert show];
    复制代码

        

    UIAlertViewStyleSecureTextInput和UIAlertViewStylePlainTextInput可以通过textFieldIndex为0来获取输入框对象。

    UIAlertViewStyleLoginAndPasswordInput可以通过textFieldIndex为0和1分别获取用户名输入框对象和密码输入框对象。

    如果一件事情你觉得难的完不成,你可以把它分为若干步,并不断寻找合适的方法。最后你发现你会是个超人。不要给自己找麻烦,但遇到麻烦绝不怕,更不要退缩。 电工查找电路不通点的最快方法是:分段诊断排除,快速定位。你有什么启示吗? 求知若饥,虚心若愚。 当你对一个事情掌控不足的时候,你需要做的就是“梳理”,并制定相应的规章制度,并使资源各司其职。
  • 相关阅读:
    Flask-1-03-HelloWorld
    Flask-1-02-安装环境
    Flask-1-01-初识Flask
    Ubuntu解决virtualbox 安装增强包的报错
    ubuntu安装软件has install-snap change in progress错误
    virtualbox
    Nginx 403 Forbidden错误的解决方法
    处理Redis报错:redis.exceptions.ResponseError: MISCONF Redis is configured to save RDB snap
    在Ubuntu18.04上安装MySQL
    Python3 错误、调试和测试
  • 原文地址:https://www.cnblogs.com/wvqusrtg/p/5165879.html
Copyright © 2011-2022 走看看