弹出日期选择器来设置日期
pop up date picker to set a date
我想在用户单击按钮并在我的代码中设置所选日期时制作一个弹出式日期选择器(仅限日期)。
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setDay:8];
[comps setMonth:9];
[comps setYear:2018];
NSDate *earlier = [[NSCalendar currentCalendar] dateFromComponents:comps];
我可以像这样输入来手动设置日期,但我不知道如何从日期选择器中设置日期。我该怎么做?
你需要做的是
- Add NSDatePicker to your view and set the settings as needed in Storyboard.
- Connect the delegates and iboutlets.
- Then get and set the date as follows
NSDate *myDate = myDatePicker.dateValue; // get
myDatePicker.dateValue = myDate; // set
我想在用户单击按钮并在我的代码中设置所选日期时制作一个弹出式日期选择器(仅限日期)。
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setDay:8];
[comps setMonth:9];
[comps setYear:2018];
NSDate *earlier = [[NSCalendar currentCalendar] dateFromComponents:comps];
我可以像这样输入来手动设置日期,但我不知道如何从日期选择器中设置日期。我该怎么做?
你需要做的是
- Add NSDatePicker to your view and set the settings as needed in Storyboard.
- Connect the delegates and iboutlets.
- Then get and set the date as follows
NSDate *myDate = myDatePicker.dateValue; // get
myDatePicker.dateValue = myDate; // set