1

I want to make a pop-up date picker (DATE ONLY) when a user clicks on a button and set the selected date in my code.

NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setDay:8];
[comps setMonth:9];
[comps setYear:2018];
NSDate *earlier = [[NSCalendar currentCalendar] dateFromComponents:comps];

I can manually set a date by typing like this but I don't know how to set the date from the date picker. How do I do it?

H.Kim
  • 277
  • 1
  • 10
  • 25
  • There are many answers on the stackoverflow here is the one among them it has all your require code. https://stackoverflow.com/questions/21011968/how-to-display-uidatepicker-if-user-hit-the-uitextfield-programmatically \ –  Feb 07 '19 at 13:59

1 Answers1

0

What you need to do is

  1. Add NSDatePicker to your view and set the settings as needed in Storyboard.
  2. Connect the delegates and iboutlets.
  3. Then get and set the date as follows
NSDate *myDate = myDatePicker.dateValue; // get
myDatePicker.dateValue = myDate; // set
GeneCode
  • 7,545
  • 8
  • 50
  • 85