iosdatetimestoryboardtimepickercustom-datetimepicker

How to create an iOS Time Picker programmatically?


I have a tiny little problem.

I'd like to implement the time picker like:

https://i.sstatic.net/G7ja3.png

This screen grab is from iOS 6's day notifications of DO NOT DISTURB

My question is how to do it ?

Any ideas ????

Are there any tutorials/resources online that you folks could suggest as how to do this ?

[edited] I should have mentioned that this for an iPhone not an iPad....

Thanks.


Solution

  • This is what I ended up doing:

    I found this popover solution -> https://github.com/werner77/WEPopover

    That created the popover I wanted, then added this bit of code to the

    - (void)viewDidAppear:(BOOL)animated method
    
    
        //  place inside a temporary view controller and add to popover
    
            UIViewController *viewCon = [[UIViewController alloc] init];
    
        //    PopOverViewController *viewCon = [[PopOverViewController alloc] init];
    
            UIDatePicker *timePick;
            timePick = [[UIDatePicker alloc]initWithFrame:CGRectMake(5, 0, 0, 0)];
            timePick.datePickerMode =UIDatePickerModeTime;
    
            [viewCon.view addSubview:timePick];
    
        //    viewCon.view = label;
    
            viewCon.contentSizeForViewInPopover = timePick.bounds.size ; // Set the content size
    
            popover = [[WEPopoverController alloc] initWithContentViewController:viewCon];
    
    
            [popover presentPopoverFromRect:CGRectMake(0, 10, 0, 120)
                                    inView:self.view
                 permittedArrowDirections:UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown
                                  animated:YES];
    

    The only problem now is resizing the picker to the width that I want....other than that, it works!

    The solutions that were presented will only work for an iPad not an iPhone....

    Thanks everyone.