美文网首页iOS UIKit框架学习
iOS-UIKit框架学习—UIAlertView

iOS-UIKit框架学习—UIAlertView

作者: Wynter_Wang | 来源:发表于2017-02-06 15:01 被阅读20次

    使用UIAlertView类向用户显示一条警告消息。警报视图的功能相似,但在外观上不同于一个动作表(UIActionSheet的一个实例)。

    @protocol UIAlertViewDelegate;
    // iOS 2.0 - iOS 9.0可用 使用UIAlertController顶替
    NS_CLASS_DEPRECATED_IOS(2_0, 9_0, "UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead") __TVOS_PROHIBITED
    @interface UIAlertView : UIView
    
    // 初始化设置标题、代理、操作按钮
    - (instancetype)initWithTitle:(nullable NSString *)title message:(nullable NSString *)message delegate:(nullable id /*<UIAlertViewDelegate>*/)delegate cancelButtonTitle:(nullable NSString *)cancelButtonTitle otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION NS_EXTENSION_UNAVAILABLE_IOS("Use UIAlertController instead.");
    // 初始化设置frame
    - (id)initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER;
    - (nullable instancetype) initWithCoder:(nonnull NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
    // 代理
    @property(nullable,nonatomic,weak) id /*<UIAlertViewDelegate>*/ delegate;
    // 标题
    @property(nonatomic,copy) NSString *title;
    // 提示内容
    @property(nullable,nonatomic,copy) NSString *message;
    
    // 在提示框中添加自定义按钮
    - (NSInteger)addButtonWithTitle:(nullable NSString *)title;
    // 返回指定索引按钮的标题
    - (nullable 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 NS_AVAILABLE_IOS(5_0);
    // 返回指定索引的文本框
    - (nullable UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex NS_AVAILABLE_IOS(5_0);
    
    
    @end
    
    __TVOS_PROHIBITED
    @protocol UIAlertViewDelegate <NSObject>
    @optional
    
    // 点击操作按钮后调用
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex NS_DEPRECATED_IOS(2_0, 9_0);
    
    // 点击取消按钮后调用
    - (void)alertViewCancel:(UIAlertView *)alertView NS_DEPRECATED_IOS(2_0, 9_0);
    // 即将弹出提示框之前调用
    - (void)willPresentAlertView:(UIAlertView *)alertView NS_DEPRECATED_IOS(2_0, 9_0);
    // 提示框弹出后调用
    - (void)didPresentAlertView:(UIAlertView *)alertView NS_DEPRECATED_IOS(2_0, 9_0);
    // 操作后将要隐藏的提示框时调用
    - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex NS_DEPRECATED_IOS(2_0, 9_0);
    // 提示框隐藏完成后调用
    - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex NS_DEPRECATED_IOS(2_0, 9_0);
    
    // 是否启用提示框中第一个非取消按钮
    - (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView NS_DEPRECATED_IOS(2_0, 9_0);
    
    @end
    
    
    // 提示框风格
    typedef NS_ENUM(NSInteger, UIAlertViewStyle) {
    UIAlertViewStyleDefault = 0, // 默认
    UIAlertViewStyleSecureTextInput, // 有密码输入框
    UIAlertViewStylePlainTextInput, // 普通文本输入框
    UIAlertViewStyleLoginAndPasswordInput // 登陆框
    } __TVOS_PROHIBITED;
    

    相关文章

      网友评论

        本文标题:iOS-UIKit框架学习—UIAlertView

        本文链接:https://www.haomeiwen.com/subject/nnfuittx.html