ios弹框

2017-08-31  本文已影响87人  一个萝卜X个坑
第一种
    
    UIAlertController *aler=[UIAlertController alertControllerWithTitle:@"温馨提示" message:@"确定取消?" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *ok=[UIAlertAction actionWithTitle:@"确定取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    }];
    UIAlertAction *cancel=[UIAlertAction actionWithTitle:@"暂不取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
           
    }];
    //设置按钮字体颜色
    [cancel setValue:[UIColor redColor] forKey:@"_titleTextColor"];
    [aler addAction:cancel];
    //添加
    [aler addAction:ok];
    //最后一步
    [self presentViewController:aler animated:YES completion:nil];
    

第二种


    UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                                  message:@"确定取消?"
                                                 delegate:self
                                        cancelButtonTitle:@"暂不取消"
                                        otherButtonTitles:@"确定取消",nil];
    [alert show];
    


代理方法

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==1) {
    }
    NSLog(@"您按下的第%ld个按钮!",buttonIndex);
}

上一篇下一篇

猜你喜欢

热点阅读