【发布时间】:2016-08-26 05:24:53
【问题描述】:
我尝试将 date piker 添加到 alertcontroller 但大小有一些问题。我不知道如何获得datepiker 的高度或只是init UIAlertController 的高度和日期piker。
所以我做了什么:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"\n\n\n\n\n\n\n\n\n\n" preferredStyle:UIAlertControllerStyleActionSheet];
UIView *viewDatePicker = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
[viewDatePicker setBackgroundColor:[UIColor clearColor]];
CGRect pickerFrame = CGRectMake(0, 0, self.view.frame.size.width, 200);
UIDatePicker *picker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[picker setDatePickerMode:UIDatePickerModeTime];
[viewDatePicker addSubview:picker];
[alertController.view addSubview:viewDatePicker];
NSDateFormatter *formate=[[NSDateFormatter alloc]init];
[formate setDateFormat:@"hh:mm a "];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
sinceDateString = [formate stringFromDate:picker.date];
[sinceDateButton setTitle:sinceDateString forState:UIControlStateNormal];
}];
[alertController addAction:defaultAction];
[self presentViewController:alertController animated:YES completion:nil];
我发现这个解决方案是同一个问题 UIAlertController 之一 *alertController = [UIAlertController alertControllerWithTitle:nil message:@"\n\n\n\n\n\n\n\n\n\n" preferredStyle:UIAlertControllerStyleActionSheet];
【问题讨论】:
-
即你当前选择日期的选择行,
-
哦,对不起,我是 iOS 开发的新手。但是“\n\n\n”只有一个解决方案添加 UIAlertController 的高度呢?
-
\n 表示创建新行
-
ok 没问题,在 google 中搜索更多你总是得到最简单的答案,做得好
标签: ios objective-c uidatepicker uialertcontroller