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

UIDatePicker *datePicker = [[UIDatePicker alloc] init]; datePicker.datePickerMode = UIDatePickerModeDate;spa

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"\n\n\n\n\n\n\n\n\n\n\n\n" message:nil   preferredStyle:UIAlertControllerStyleActionSheet];orm

[alert.view addSubview:datePicker];對象

UIAlertAction *ok = [UIAlertAction actionWithTitle:@"肯定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {字符串

        NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];string

        //實例化一個NSDateFormatter對象it

        [dateFormat setDateFormat:@"yyyy-MM-dd"];//設定時間格式io

        NSString *dateString = [dateFormat stringFromDate:datePicker.date];date

        //求出當天的時間字符串im

        NSLog(@"%@",dateString);margin

    }];

 UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

  }];

[alert addAction:ok];

[alert addAction:cancel];

[self presentViewController:alert animated:YES completion:^{ }];

相關文章
相關標籤/搜索