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

iOS-UIKit框架学习—UIAlertController

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

UIAlertController对象向用户展示一个提示消息。这个类替换了用于显示提示 UIActionSheetUIAlertViewclasses类。可以使用presentViewController:animated:completion:方法配置你想要的事件和风格。

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

NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertController : UIViewController
// 创建并返回一个用户展示提示的控制器
+ (instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle;
// 添加UIAlertAction到控制器中
- (void)addAction:(UIAlertAction *)action;
// 用户可以操作的事件数组
@property (nonatomic, readonly) NSArray<UIAlertAction *> *actions;
// 设置首选的事件
@property (nonatomic, strong, nullable) UIAlertAction *preferredAction NS_AVAILABLE_IOS(9_0);
// 添加输入框
- (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

// 事件风格
typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
UIAlertActionStyleDefault = 0, // 默认
UIAlertActionStyleCancel, // 取消
UIAlertActionStyleDestructive // 红色
} NS_ENUM_AVAILABLE_IOS(8_0);

// 控制器风格
typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
UIAlertControllerStyleActionSheet = 0, // ActionSheet
UIAlertControllerStyleAlert // AlertView
} NS_ENUM_AVAILABLE_IOS(8_0);

相关文章

  • iOS-UIKit框架学习—UIAlertController

    UIAlertController对象向用户展示一个提示消息。这个类替换了用于显示提示 UIActionSheet...

  • iOS-UIKit框架学习—UIDatePicker

    UIDatePicker类实现了一个对象,它使用多个旋转的车轮,以允许用户选择日期和时间。iPhone的例子是一个...

  • iOS-UIKit框架学习—UITextView

    UITextView的类实现一个滚动的,多行文本区域的行为。类支持使用自定义字体,颜色,和对齐的文本的显示,同时还...

  • iOS-UIKit框架学习—UIScrollView

    UIScrollView的类提供支持显示的内容是大于应用程序的窗口大小。它可以使用户内滚动的内容,通过刷卡手势,和...

  • iOS-UIKit框架学习—UIAlertView

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

  • iOS-UIKit框架学习—UIActionSheet

    使用UIActionSheet类可以把一套如何继续给定任务的替代品给用户。您还可以使用行动表,以提示用户确认是否有...

  • iOS-UIKit框架学习—UITableView

    UITableView在iOS开发中是使用最广泛的一个控件,用于展示单个项目数据的列表,同时也可以进行选择和编辑操作。

  • iOS-UIKit框架学习—UIWebView

    您使用了UIWebView类,在您的应用程序中嵌入网页内容。要做到这一点,你只需创建一个UIWebView对象,将...

  • iOS-UIKit框架学习—UISearchBar

    UISearchBar类实现一个基于文本的搜索的文本字段控制。该控件提供了一个搜索按钮,输入文字的文本字段书签“按...

  • iOS-UIKit框架学习—UIWindow

    一个UIWindow对象提供了您的应用程序的用户界面的背景和提供了重要的事件处理行为。Windows没有自己的任何...

网友评论

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

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