標籤:
UIDatePicker *datePicker = [[UIDatePicker alloc] init]; datePicker.datePickerMode = UIDatePickerModeDate;UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"\n\n\n\n\n\n\n\n\n\n\n\n" message:nil preferredStyle:UIAlertControllerStyleActionSheet];[alert.view addSubview:datePicker];UIAlertAction *ok = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init]; //執行個體化一個NSDateFormatter對象 [dateFormat setDateFormat:@"yyyy-MM-dd"];//設定時間格式 NSString *dateString = [dateFormat stringFromDate:datePicker.date]; //求出當天的時間字串 NSLog(@"%@",dateString); }]; UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { }];[alert addAction:ok];[alert addAction:cancel];[self presentViewController:alert animated:YES completion:^{ }];
需要注意的是,這裡沒有設定地區時間
[datePicker setLocale:[[NSLocale alloc]initWithLocaleIdentifier:@"zh_Hans_CN"]];
IOS UIAlertController 彈出框中添加視圖(例如日期選取器等等)