在8.3之后,以前的办法就不可以用了,而下面这个方法在8.0之后就已经使用。
//alert的按钮样式
typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
UIAlertActionStyleDefault = 0,
UIAlertActionStyleCancel,
UIAlertActionStyleDestructive
} NS_ENUM_AVAILABLE_IOS(8_0);
//alert控制器的样式,就是就是alert和actionsheet的两种情况
typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
UIAlertControllerStyleActionSheet = 0,
UIAlertControllerStyleAlert
} NS_ENUM_AVAILABLE_IOS(8_0);
//UIAlertAction这个类的属性,也就是设置相关的sheet(和alert两种都是一样,下面将会值介绍一种)
NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertAction : NSObject <NSCopying>
//初始化的方法
+ (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
//UIAlertController类
NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertController : UIViewController
//初始化一个方法
+ (instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle;
//属性,标题、信息
@property (nullable, nonatomic, copy) NSString *title; //标题
@property (nullable, nonatomic, copy) NSString *message;//信息
@property (nonatomic, readonly) UIAlertControllerStyle preferredStyle;//样式
//增加动作?这个方法么有用过
- (void)addAction:(UIAlertAction *)action;
//属性action是一个数组的类型
@property (nonatomic, readonly) NSArray<UIAlertAction *> *actions;
//偏向,应该是默认的动作
@property (nonatomic, strong, nullable) UIAlertAction *preferredAction NS_AVAILABLE_IOS(9_0);//在alert上增textfield
- (void)addTextFieldWithConfigurationHandler:(void (^ __nullable)(UITextField *textField))configurationHandler;
@end
NS_ASSUME_NONNULL_END