自封时间选择滚轮

来源:互联网 发布:js开发框架 编辑:程序博客网 时间:2024/04/28 03:06
- (void)pickViewCount_str:(void(^)(NSString * datestr))count_str{
    UIAlertController* alertVc=[UIAlertController alertControllerWithTitle:@"\n\n\n\n\n\n\n\n\n\n\n" message:nil preferredStyle:(UIAlertControllerStyleActionSheet)];
    UIDatePicker* datePicker=[[UIDatePicker alloc]init];
    datePicker.datePickerMode = UIDatePickerModeDate;
    [datePicker setMaximumDate:[NSDate date]];
    NSLocale *locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"];
    datePicker.locale = locale;
    // 设置DatePicker的center
    CGPoint center = datePicker.center;
    center.x = alertVc.view.frame.size.width * 0.48;
    datePicker.center = center;
    
    UIAlertAction* ok=[UIAlertAction actionWithTitle:@"确认" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {
        NSDate* date=[datePicker date];
        NSDateFormatter* formatter=[[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"yyyy-MM-dd"];
        
        _timestring=[formatter stringFromDate:date];
        count_str(_timestring);
    }];
    UIAlertAction* no=[UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleDefault) handler:nil];
    [alertVc.view addSubview:datePicker];
    [alertVc addAction:ok];
    [alertVc addAction:no];
    [self presentViewController:alertVc animated:YES completion:nil];
}




//调用
 [self pickViewCount_str:^(NSString *count_str) {
            NSLog(@"===-=--=%@",count_str);
        }];




0 0
原创粉丝点击