• UIkit框架之UIalert(iOS 9之后就不用这个了)


    IOS中UIAlertView(警告框)常用方法总结

    一、初始化方法

    - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id /*<UIAlertViewDelegate>*/)delegate cancelButtonTitle:(NSString*)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...;

    这个方法通过设置一个标题,内容,代理和一些按钮的标题创建警告框,代码示例如下:

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

    效果如下:

    130508_XklY_2340880.png

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

    130912_SSoj_2340880.png

    如果按钮数量超出屏幕显示范围,则会创建类似tableView的效果。

    二、属性与方法解析

    标题属性

    @property(nonatomic,copy) NSString *title;

    内容属性

    @property(nonatomic,copy) NSString *message;

    添加一个按钮,返回的是此按钮的索引值

    - (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;

    风格的枚举如下

    1
    2
    3
    4
    5
    6
    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;

    辅助功能:UIAlertViewStyle的类型:

        UIAlertViewStyleDefault = 0:一个标准的警告框

    UIAlertViewStyleSecureTextInput, :一个能够让用户输入文本的警告框,并且文本框是掩盖的

    UIAlertViewStylePlainTextInput, :一个能够让用户 输入文本的警告框

    UIAlertViewStyleLoginAndPasswordInput :一个能够让用户输入账号和密码的警告框

  • 相关阅读:
    【网络安全】telnet 登陆远程服务器
    【网络安全】window 快速搭建 ftp 及 多种访问方式
    科普:PCI-E插槽都有哪些样子?
    Memory及其controller芯片整体测试方案(下篇)
    Memory及其controller芯片整体测试方案(上篇)
    超通俗易懂科普:什么是光通信?
    PCB各层介绍及AD软件画PCB时的规则
    第一次接触FPGA至今,总结的宝贵经验
    嵌入式码农的10年Bug调试经验,值得一看
    做嵌入式驱动的,你一定要挺住!
  • 原文地址:https://www.cnblogs.com/lelun/p/5681967.html
Copyright © 2020-2023  润新知