iOS8 UIAlertController彈出框中添加視圖(例如日期選擇器等等)


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:^{ }];

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM