1

In my app I need to have a Date Picker on UIAlert view

I implemented this by following Date Picker in Alert View

But while I'm using this date picker in alert view there is some height issues in alert view I tried to set the frame for the alert view but it doesn't sets what to do?

enter image description here

My code:

-(void)SetDate
{
      dobPicker = [[UIDatePicker alloc] init];
      dobPicker.frame=CGRectMake(20, 25.0, 240.0, 150.0);
      dobPicker.datePickerMode = UIDatePickerModeDateAndTime;

      [dobPicker setDate:[NSDate date]];

            UIAlertView *dAlert = [[UIAlertView alloc] initWithTitle:@"Set Date" message:@"nnnnnnn" delegate:self cancelButtonTitle:@"Set Current Date" otherButtonTitles:@"Set New Date", nil];
   dAlert.frame=CGRectMake(10, 10.0, 300.0, 400.0);
  dAlert.delegate = self;
  [dAlert addSubview:dobPicker];
  [dAlert show];
  [dAlert release];
}


- (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
      NSDate *date = [dobPicker date];
      NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
      [dateFormatter setDateFormat:(NSString*) @"yyyy-MM-dd"];

      NSLog(@"-------------------------- %@", [dateFormatter stringFromDate:date]);
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
user1811427
  • 359
  • 2
  • 6
  • 17
  • ref : http://stackoverflow.com/questions/12166734/add-uidatepicker-to-uialertview http://code.thewebanalyzers.com/2011/12/showing-datepicker-in-alert-view-without-using-interface/ – Sagar... Jan 09 '13 at 10:27
  • Possible duplicate of [Add UIDatePicker to UIAlertView](https://stackoverflow.com/questions/12166734/add-uidatepicker-to-uialertview) – Cœur Mar 12 '18 at 08:19

2 Answers2

1

Transform Scale your UIAlertView like this:

 dAlert.transform = CGAffineTransformScale(dAlert.transform,xScaleHere, yScaleHere); //provide your scaling points sx and sy according to your requirement.
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
1

simple: ... [UIAlertView..

message:@"\n\n\n\n\n\n\n\n\n\n\n"

...

also.. to view the title of UIAlertView.. try to modify "y" from 25 to 40.. (test)

dobPicker.frame=CGRectMake(20, 40.0, ...

TonyMkenu
  • 7,597
  • 3
  • 27
  • 49