zoukankan      html  css  js  c++  java
  • UIAlertView

    代码示例如下:

    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"这是一个警告框" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    
    [alert show];

    注意:如果按钮数超过两个,将会创建成如下样子:

    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"这是一个警告框" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"button1", @"button2", @"button3", @"button4", @"button5", nil];
        
    [alert show];

    如果高度超过屏幕,就会像tableView一样:

    添加一个按钮,返回的是此按钮的索引值
    - (NSInteger)addButtonWithTitle:(NSString *)title;   
    
    返回根据按钮索引按钮标题 
    - (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;
    
    获取按钮数量
    @property(nonatomic,readonly) NSInteger numberOfButtons;
    
    设置将某一个按钮设置为取消按钮
    @property(nonatomic) NSInteger cancelButtonIndex;
    
    返回其他类型按钮第一个的索引值
    @property(nonatomic,readonly) NSInteger firstOtherButtonIndex;
    
    警告框是否可见
    @property(nonatomic,readonly,getter=isVisible) BOOL visible;
    
    显现警告框
    - (void)show;
    
    代码模拟点击按钮消失触发方法
    - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
    
    设置警告框风格
    @property(nonatomic,assign) UIAlertViewStyle alertViewStyle;
    
    风格的枚举如下:
    typedef NS_ENUM(NSInteger, UIAlertViewStyle) {
        UIAlertViewStyleDefault = 0,//默认风格
        UIAlertViewStyleSecureTextInput,//密码输入框风格
        UIAlertViewStylePlainTextInput,//普通输入框风格
        UIAlertViewStyleLoginAndPasswordInput//账号密码框风格
    };
    
    这个方法设置文本输入框的索引
    - (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex;
    
    
    UIAlertViewDelegate的方法
    
    点击按钮时触发的方法
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
    
    将要展现警告框时触发的方法
    - (void)willPresentAlertView:(UIAlertView *)alertView;
    
    已经展现警告框时触发的方法
    - (void)didPresentAlertView:(UIAlertView *)alertView;
    
    警告框将要消失时触发的方法
    - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex;
    
    警告框已经消失时触发的方法
    - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex; 
    
    设置是否允许第一个按钮不是取消按钮
    - (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView;
  • 相关阅读:
    [LintCode] Set Matrix Zeros
    [LintCode] Identify Celebrity
    [LintCode] Edit Distance
    [LintCode] Edit Distance II
    [LintCode] Strings Serialization
    二十七. Keepalived热备 Keepalived+LVS 、 HAProxy服务器
    二十六. 集群及LVS简介 LVS-NAT集群 LVS-DR集群
    二十五 存储技术与应用 iSCSI技术应用 、 udev配置 NFS网络文件系统 、 Multipath多路径 、 NFS网络文件系统 、 udev配置
    二十三.Subversion基本操作、使用Subversion协同工作、制作nginx的RPM包
    二十二. 安装部署Tomcat服务器、使用Tomcat部署虚拟主机、使用Varnish加速Web
  • 原文地址:https://www.cnblogs.com/pengyunjing/p/5907727.html
Copyright © 2011-2022 走看看