系統(tǒng)提供的警告框有兩種類型卵慰,類型及使用方式如下:
樣式如圖:
//警告框代碼
-(void)presentAlert{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警 告" message:@"這里寫警告的內(nèi)容完慧!" 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:@"這里寫警告的內(nèi)容姐呐!" 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];
}