UIAlertController 的简单使用方法

- (void)viewDidLoad {

    [super viewDidLoad];

    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];

    btn.frame=CGRectMake(10, 60, 80, 30);

    [btn setTitle:@"提示框" forState:UIControlStateNormal];

    btn.backgroundColor=[UIColor redColor];

    [btn addTarget:self action:@selector(gotoAlertVC) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:btn];

}

-(void)gotoAlertVC{

    UIAlertController *alertVC=[UIAlertController alertControllerWithTitle:@"提示信息" message:@"iOSQQ技术交流群436337987" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *sureAction=[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        NSLog(@"确定加入");

    }];

    UIAlertAction *cancelAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

        NSLog(@"取消加入");

    }];

    [alertVC addAction:sureAction];

    [alertVC addAction:cancelAction];

    [self presentViewController:alertVC animated:YES completion:nil];

}

 

posted @ 2016-01-08 12:03  shao621  阅读(158)  评论(0编辑  收藏  举报