UIAlertController.h


#if USE_UIKIT_PUBLIC_HEADERS || !__has_include(<UIKitCore/UIAlertController.h>)
//
//  UIAlertController.h
//  UIKit
//
//  Copyright (c) 2014-2018 Apple Inc. All rights reserved.
//
#import <UIKit/UIViewController.h>
#import <UIKit/UISpringLoadedInteractionSupporting.h>
NS_ASSUME_NONNULL_BEGIN





/* 警告行为风格 <枚举> */
typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
    UIAlertActionStyleDefault = 0,  // 默认样式
    UIAlertActionStyleCancel,       // 取消样式(最多只能有一个此类型的按钮)
    UIAlertActionStyleDestructive,  // 破坏样式(红色警告样式)
} NS_ENUM_AVAILABLE_IOS(8_0);

/* 警告控制器风格 <枚举> */
typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
    UIAlertControllerStyleActionSheet = 0,  // 底部弹出样式
    UIAlertControllerStyleAlert             // 中间弹出样式(1-2个事件按钮,弹窗横着摆放两个;2个事件按钮以上,竖着往下排)
} NS_ENUM_AVAILABLE_IOS(8_0);





#pragma mark - 行为 <分类>
NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertAction : NSObject <NSCopying>
/**
 指定实例化方法

 @param title 行为名称
 @param style 行为风格
 @param handler 处理完行为的回调
 @return UIAlertAction
 */
+ (instancetype)actionWithTitle:(nullable NSString *)title style:(UIAlertActionStyle)style handler:(void (^ __nullable)(UIAlertAction *action))handler;
// 获取标题文字
@property (nullable, nonatomic, readonly) NSString *title;
// 获取风格
@property (nonatomic, readonly) UIAlertActionStyle style;
// 是否启动
@property (nonatomic, getter=isEnabled) BOOL enabled;
@end





#pragma mark - 警告控制器 Class
#pragma mark -
/*
 - UIAlertController
    向用户显示警报消息的控制器
 - 概述
    可以配置警报/操作表视图(即底部弹出操作表或中间弹出报警,在iOS8以后合并到UIAlertController)
    弹出方式用 Modal
    除了向用户显示消息之外,您还可以将一些操作与UIAlertController关联,为用户提供响应方式.
    用-addAction:方法添加操作,UIAlertController会配置一个包含操作详细信息的按钮;当用户点击该操作时,UIAlertController会执行在创建操作对象时对应的Block回调
    此控制器视图层次结构是私有的,不得修改,不能重写
 */
NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertController : UIViewController
/**
 指定实例化方法

 @param title 标题文字
 @param message 副标题文字
 @param preferredStyle 警告控制器风格
 @return UIAlertController
 */
+ (instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle;
/**
 添加行为(UIAlertAction会根据3种不同的按钮样式排序;单一一种样式根据添加顺序排序)

 @param action 要添加的行为
 */
- (void)addAction:(UIAlertAction *)action;

// 获取添加的所有行为
@property (nonatomic, readonly) NSArray<UIAlertAction *> *actions;
// 设置首选行为(把指定行为字体加粗)
@property (nonatomic, strong, nullable) UIAlertAction *preferredAction NS_AVAILABLE_IOS(9_0);

/**
 添加TF输入框(UIAlertControllerStyleAlert风格可用;控制器会储存TF的信息,方便之后对TF的操作)

 @param configurationHandler TF输入框的回调(可对TF进行配置)
 */
- (void)addTextFieldWithConfigurationHandler:(void (^ __nullable)(UITextField *textField))configurationHandler;
// 获取添加的所有TF
@property (nullable, nonatomic, readonly) NSArray<UITextField *> *textFields;
// 设置标题文字
@property (nullable, nonatomic, copy) NSString *title;
// 设置消息文字
@property (nullable, nonatomic, copy) NSString *message;
// 获取控制器风格
@property (nonatomic, readonly) UIAlertControllerStyle preferredStyle;
@end






#pragma mark - 开放加载 <分类>
#if TARGET_OS_IOS
@interface UIAlertController (SpringLoading) <UISpringLoadedInteractionSupporting>
@end





#endif
NS_ASSUME_NONNULL_END
#else
#import <UIKitCore/UIAlertController.h>
#endif

猜你喜欢

转载自blog.csdn.net/weixin_34416754/article/details/87537939