我有一個自定義警報視圖控制器來從日期選擇器中選擇日期,但我很困惑,我怎麼能在警報視圖控制器中添加兩個按鈕和當用戶單擊按鈕比它顯示警報視圖控制器中的日期選擇器,以及如何更改警報視圖控制器的顏色。我的代碼,自定義警報視圖控制器在IOS中選擇日期
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"\n\n\n\n\n\n\n\n\n\n\n" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIDatePicker *picker = [[UIDatePicker alloc] init];
[picker setDatePickerMode:UIDatePickerModeDate];
[alertController.view addSubview:picker];
[alertController addAction:({
UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"OK");
NSLog(@"%@",picker.date);
}];
action;
})];
UIPopoverPresentationController *popoverController = alertController.popoverPresentationController;
popoverController.sourceView = sender;
popoverController.sourceRect = [sender bounds];
[self presentViewController:alertController animated:YES completion:nil];
如果你看看docs for UIAlertViewController https://developer.apple.com/documentation/uikit/uialertcontroller你會發現你真的不應該對它的視圖層次結構進行討論。你只是在爲自己排憂解難。 – Abizern