我有一个自定义警报视图控制器来从日期选择器中选择日期,但我很困惑,我怎么能在警报视图控制器中添加两个按钮和当用户单击按钮比它显示警报视图控制器中的日期选择器,以及如何更改警报视图控制器的颜色。我的代码,自定义警报视图控制器在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