Reputation: 2491
This is two questions..
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?
Upvotes: 0
Views: 1439
Reputation: 1605
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)
Upvotes: 1