0

This is two questions..

  1. How do I place my UIDatePicker on the bottom of the page?
  2. How can I get the date from the picker.

Here is my code for when I add the date picker:

picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
[picker addTarget:self action:@selector(customDate:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:picker];

and here is my customDate: function

- (void)customDate:(id)sender {

}

so... what do I do? How do I do this?

Jason Silberman
  • 2,471
  • 6
  • 29
  • 47

1 Answers1

1

Should look something like this:

- (void) customDate:(id)sender{
    NSLocale *usLocale = [[NSLocale alloc]
        initWithLocaleIdentifier:@"en_US"];

    NSDate *pickerDate = [picker date];
    NSString *selectionString = [[NSString alloc] initWithFormat:@"%@",
         [pickerDate descriptionWithLocale:usLocale]];
    //do something with the date string
}

Put what you need to do in there with the string, whether it be set a label or whatever.

And to set the frame:

picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 250, 320, 100)];

The numbers there signify the location and size of the date picker, so it goes (x location, y location, width, height)

JeffN
  • 1,575
  • 15
  • 26