UIAlertController使用

来源:互联网 发布:淘宝皇冠店铺100强 编辑:程序博客网 时间:2024/05/18 05:40
////  ViewController.m//#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    [_alertButton addTarget:self action:@selector(addAlertVC) forControlEvents:UIControlEventTouchUpInside];}-(void)addAlertVC{    /*     UIAlertActionStyleDefault = 0,默认样式     UIAlertActionStyleCancel,  取消操作,保留原先样子     UIAlertActionStyleDestructive  可能有删除、改变数据     */    /*     UIAlertControllerStyleActionSheet = 0,下方弹出     UIAlertControllerStyleAlert  弹框     */    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"选择分享的平台" message:@"" preferredStyle:UIAlertControllerStyleAlert];    UIAlertAction * alertAction1 = [UIAlertAction actionWithTitle:@"新浪" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {        NSLog(@"新浪");    }];    UIAlertAction * alertAction2 = [UIAlertAction actionWithTitle:@"微信" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {        NSLog(@"微信");           }];    UIAlertAction * alertAction3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {            NSLog(@"取消");           }];    [alert addAction:alertAction1];    [alert addAction:alertAction2];    [alert addAction:alertAction3];    [self presentViewController:alert animated:true completion:nil];}@end

效果图展示

这里写图片描述

这里写图片描述