UIAlertController中添加DatePicker

 

   直接複製到你要點擊的地方spa

    UIDatePicker *datePicker = [[UIDatePicker alloc] init];orm

    datePicker.datePickerMode = UIDatePickerModeTime;字符串

    datePicker.frame = CGRectMake(0, 40,272,90);string

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"設置\n\n" message:nil preferredStyle:UIAlertControllerStyleAlert];it

    [alert.view addSubview:datePicker];io

 

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

        

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

        [dateFormat setDateFormat:@"HH:mm"];//設定時間格式im

        

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

        int hh = [[dateString substringToIndex:2]intValue];

        int mm = [[dateString substringFromIndex:3]intValue];

        [self settingWithHour:hh WithMin:mm];

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

        NSLog(@"%d,%d",hh,mm);

    }];

    

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

        

    }];

    

    [alert addAction:ok];//添加按鈕

    

    [alert addAction:cancel];//添加按鈕

    //modal的形式

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

相關文章
相關標籤/搜索