1

嗨,我有一个要求,我需要在仅限 iPad 的应用程序的 uiactionsheet 中显示日期和时间。

我的 google /sof 搜索将我带到以下资源 https://github.com/TimCinel/ActionSheetPicker

ActionSheetDatePicker *actionSheetPicker = [[ActionSheetDatePicker alloc] initWithTitle:@"" datePickerMode:UIDatePickerModeDateAndTime selectedDate:[NSDate date] target:self action:@selector(onDateSelected:element:) origin:sender];
actionSheetPicker.hideCancel = YES;
[actionSheetPicker showActionSheetPicker];

它很好用,除了我的生活我找不到可以设置最小、最大日期和间隔的地方。请如果有人使用过这可能会有所帮助。谢谢

4

4 回答 4

1

在这里,我在 iPhone/iPod 上使用 Actionsheet + UIDatePicker,但在 iPAD 上使用 POPOVERCONTROLLER + UIDATEPICKER。

- (IBAction)showAction:(id)sender
{

aac = [[UIActionSheet alloc] initWithTitle:@""
                                                 delegate:self
                                        cancelButtonTitle:nil
                                   destructiveButtonTitle:nil
                                        otherButtonTitles:nil];

self.dtPicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];


UIToolbar *pickerDateToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerDateToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerDateToolbar sizeToFit];

NSMutableArray *barItems = [[NSMutableArray alloc] init];


UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(DatePickerCancelClick:)];
[barItems addObject:cancelBtn];

UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(DatePickerDoneClick:)];

[barItems addObject:doneBtn];


[pickerDateToolbar setItems:barItems animated:NO];

if (IS_IPHONE) {

    [aac addSubview:pickerDateToolbar];
    [aac addSubview:dtPicker];
    [self.view addSubview:aac];
}
else {
    UIView *view = [[UIView alloc] init];

    [view addSubview:pickerDateToolbar];
    [view addSubview:dtPicker];

    UIViewController *vc = [[UIViewController alloc] init];
    [vc setView:view];
    [vc setContentSizeForViewInPopover:CGSizeMake(320, 260)];

    popover = [[UIPopoverController alloc] initWithContentViewController:vc];
    popover.delegate = self;



    [popover presentPopoverFromRect:myButton.bounds inView:myButton
           permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];


}
}

//希望你明白了。谢谢

于 2013-04-15T10:32:02.087 回答
1
 UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Date Picker" 
                                                  delegate:self
                                         cancelButtonTitle:@"Cancel"
                                    destructiveButtonTitle:nil
                                         otherButtonTitles:nil];

    // Add the picker
    UIDatePicker *pickerView = [[UIDatePicker alloc] init];
    pickerView.datePickerMode = UIDatePickerModeDateAndTime;
    [menu addSubview:pickerView];
    [menu showInView:self.view];    
    [menu setBounds:CGRectMake(0,0,320, 300)];

    CGRect pickerRect = pickerView.bounds;
    pickerRect.origin.y = -100;
    pickerView.bounds = pickerRect;

上面的代码对于添加UIDatePickerUIActionSheet. 在上面的代码中,您可以使用显示日期和时间UIDatePicker

于 2013-04-15T10:25:08.293 回答
1

根据 ibiren在 UIPopover thread中 UIDatePicker 的建议,我最终使用了这段代码。

UIViewController* popoverContent = [[UIViewController alloc] init]; //ViewController

UIView *popoverView = [[UIView alloc] init];   //view
popoverView.backgroundColor = [UIColor blackColor];

UIDatePicker *datePicker=[[UIDatePicker alloc]init];//Date picker
datePicker.frame=CGRectMake(0,44,320, 216);
datePicker.datePickerMode = UIDatePickerModeDateAndTime;
[datePicker setMinuteInterval:5];
[datePicker setTag:10];
[datePicker addTarget:self action:@selector(Result) forControlEvents:UIControlEventValueChanged];
[popoverView addSubview:datePicker];

popoverContent.view = popoverView;
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
popoverController.delegate=self;
[popoverContent release];

[popoverController setPopoverContentSize:CGSizeMake(320, 264) animated:NO];
[popoverController presentPopoverFromRect:tempButton.frame inView:self.view     permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
//tempButton.frame where you need you can put that frame
于 2013-04-15T11:35:16.480 回答
-1

我知道这个答案来晚了。但是对于任何想使用这个库的人来说……新版本的 ActionSheetDatePicker 具有以下属性:

NSDate *minimumDate;
NSInteger minuteInterval;
NSCalendar *calendar;
NSTimeZone *timeZone;
NSLocale *locale;

允许您根据需要修改 DatePicker 的基本选项。

于 2014-08-27T12:59:16.787 回答