iOS基本UI控件的使用

iOS小控件的使用

UIAlertController

UIAlertView用来给用户展示警告信息。这个类是在iOS 8.0之后出现的,用来替代UIActionSheet(从底部冒出) 和 UIAlertView(从中间出现)。确定了警告控制器的动作方式和style之后,使用 presentViewController:animated:completion: 方法来展示。

typedef enum UIAlertControllerStyle: NSInteger {
   UIAlertControllerStyleActionSheet = 0, //提示信息从底部弹出
   UIAlertControllerStyleAlert //提示信息从中间弹出
} UIAlertControllerStyle;

使用方法:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"My Alert" message:@"This is an alert" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        // 点击该按钮后的逻辑 
 }];
// 添加action
[alert addAction:defaultAction];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {}];
UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {}];
[alert addAction:cancelAction];
[alert addAction:deleteAction];
// 弹出警告框    
[self presentViewController:alert animated:YES completion:nil];
UIAlertControllerStyleActionSheet
UIAlertControllerStyleAlert
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容