系统提供的警告框有两种类型,类型及使用方式如下:
样式如图:
//警告框代码
-(void)presentAlert{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警 告" message:@"这里写警告的内容!" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *centain = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:centain];
[self presentViewController:alert animated:YES completion:nil];
}
样式如图:
//表单警告框代码
-(void)presentAlertSheet{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警 告" message:@"这里写警告的内容!" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *centain = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:centain];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];
}
alertView样式图:
//alertView代码
-(void)addAlertView{
UIAlertView *alertView = [[UIAlertView alloc]initWithFrame:CGRectMake(100, 200, 200, 100)];
alertView.backgroundColor = [UIColor redColor];
[self.view addSubview:alertView];
}