码迷,mamicode.com
首页 > 其他好文 > 详细

UIAlertController

时间:2016-09-01 18:37:44      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

楼主在整理项目的警告,于是乎你懂的。

然后自己整理了一下以后方便自己忘了之后能及时找到它

 

关于UIAlertController .h文件的解析

/**
 关于UIAlertController的解析
 */

#import <UIKit/UIViewController.h>
//
NS_ASSUME_NONNULL_BEGIN

//枚举 UIAlertActionStyle
typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
    UIAlertActionStyleDefault = 0,//默认
    UIAlertActionStyleCancel,//取消
    UIAlertActionStyleDestructive//颜色突出的
} NS_ENUM_AVAILABLE_IOS(8_0);
//枚举 UIAlertControllerStyle
typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
    UIAlertControllerStyleActionSheet = 0,//actionSheet// 从底部弹出
    UIAlertControllerStyleAlert//alertView 从中间弹出
} NS_ENUM_AVAILABLE_IOS(8_0);

/* ********************************UIAlertAction********************************/
//aletviewCon的内部模块按钮
NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertAction : NSObject <NSCopying>
/**
 *  类方法创建
 *
 *  @param title   标题内容
 *  @param style   action的样式
 *  @param handler 点击后执行的操作block模式
 *
 *  @return 
 */
+ (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
/**
 *  工厂方法创建
 *
 *  @param title          标题
 *  @param message        详细标题
 *  @param preferredStyle 样式
 *
 *  @return
 */
+ (instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle;
/**
 *  添加按钮
 *
 *  @param action
 */
- (void)addAction:(UIAlertAction *)action;
//按钮数组()只读的
@property (nonatomic, readonly) NSArray<UIAlertAction *> *actions;
//偏好action,将以后的action设置为偏好action,action的字体会加粗
@property (nonatomic, strong, nullable) UIAlertAction *preferredAction NS_AVAILABLE_IOS(9_0);
//alerviewstyle添加文本框的方法 可在block设置textfield的属性
- (void)addTextFieldWithConfigurationHandler:(void (^ __nullable)(UITextField *textField))configurationHandler;
@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

NS_ASSUME_NONNULL_END

 

使用代码

在button点击事件中

- (IBAction)button:(id)sender {
//    UIAlertController *alertCon = [UIAlertController alertControllerWithTitle:@"提示" message:@"wocao" preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertController *alertCon = [UIAlertController alertControllerWithTitle:@"提示" message:@"wocao" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"默认" style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"不知道" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"wocaodelai ");
    }];
//    action3.enabled = NO;
    [alertCon addAction:action1];
    [alertCon addAction:action2];
    [alertCon addAction:action3];
    alertCon.preferredAction = action3;
    [alertCon addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.textColor = [UIColor redColor];
    }];
    [alertCon addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.textColor = [UIColor yellowColor];
        textField.textAlignment = NSTextAlignmentRight;
    }];
//    NSLog(@"textFields %@", alertCon.textFields);
    [self presentViewController:alertCon animated:YES completion:nil];
}

 

UIAlertController

标签:

原文地址:http://www.cnblogs.com/ddavidXu/p/5830527.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!