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;
  • 相关阅读:
    [MySQL] InnoDB三大特性之 插入缓冲
    字节对齐《c和指针》笔记包含位域结构体的内存对齐(32bit,GCC)
    反编译想到的代码安全问题
    剪切\编辑歌曲软件
    照片行【生活随笔】井冈山之行
    埃里克食品浅谈垃圾食品
    C++ 堆排序实现
    SQLite数据库
    全光网络的前世今生
    hdu1201(从出生长18岁经过多少天)
  • 原文地址:https://www.cnblogs.com/pengyunjing/p/5907727.html
Copyright © 2011-2022 走看看