How to display datepicker like that in iOS 7 calendar UIDatePicker

拟墨画扇 提交于 2019-12-12 08:51:11

问题


I'm new to iOS development, learning bits and pieces. I've few more queries in continuation to another thread (iOS7: How does Apple make a navigation controller look like a uiactionsheet in the calendar app) on iOS 7 new event creation in default calendar that's shown when we click + on UINavigationBar (I assume).

Does anyone know how to create UIDatePicker so that its displayed/hidden when I click on Start/End date field? I saw one video where UIActionSheet was used in XCode 4.5, but in that user needs to click on Done etc button to hide it. In iOS 7 calendar its hidden when I click outside picker i.e. on Start Date field. I hope question is clear?

Kindly advise how to achieve this feature?


回答1:


You can try and use the OCCalendarController, Its so simple and comfortable. Just download the zipped file and get all the files named after the prefix OC.

Of which in OCCalendarViewController.m you can make the necessary changes by adding Okay or Cancel buttons programmatically, yourself.

To call the calendar view in your main file use the lines,

//Here's where the magic happens calVC = [[OCCalendarViewController alloc] initAtPoint:CGPointMake(150, 50) inView:self.view]; calVC.delegate = self; [self.view addSubview:calVC.view];

Also do include the following delegate to receive the date selection(if the user selects a date or date range)

- (void)completedWithStartDate:(NSDate *)startDate endDate:(NSDate *)endDate {

Finally you can also customize the arrow(which appears along with the calendar view) by using the code,

[OCCalendarViewController alloc] initAtPoint:insertPoint inView:self.view arrowPosition:OCArrowPositionRight]

Rest of the details can be found on the read me file. Try out yourself, It'll work like a charm.Cheers!




回答2:


My open source project HSUDatePicker may help you. https://github.com/tuoxie007/HSUDatePicker



来源:https://stackoverflow.com/questions/19447871/how-to-display-datepicker-like-that-in-ios-7-calendar-uidatepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!