简体   繁体   English

日期选择器iOS

[英]Date picker iOS

I am really new to iOS development, and I know this will be a silly question but I need to do something like this: I have a button in my view, when I press it , then a date picker should appear. 我真的是iOS开发的新手,我知道这将是一个愚蠢的问题,但我需要执行以下操作:视图中有一个按钮,当按下它时,应该会出现一个日期选择器。 When a date is selected, date picker should disappear and the selected date should be shown in my UILabel. 选择日期后,日期选择器应消失,并且所选日期应显示在我的UILabel中。

How can I do this? 我怎样才能做到这一点? I am using Xcode 5. I want to do this for iOS 7. 我正在使用Xcode5。我想针对iOS 7执行此操作。

Please give me tutorial links, code samples, steps to follow or anything which I need to do this. 请给我教程链接,代码示例,要遵循的步骤或我需要执行的任何操作。 Please help me. 请帮我。

Thank you! 谢谢!

I just found this, maybe it will help :) 我刚刚发现了这个,也许会有所帮助:)

http://masteringios.com/blog/2013/10/31/ios-7-in-line-uidatepicker/ http://masteringios.com/blog/2013/10/31/ios-7-in-line-uidatepicker/

//edit: I skimmed through the tutorial, this is not a good example. // edit:我浏览了本教程,这不是一个好例子。

Use UIDatePicker is better. 使用UIDatePicker更好。

Add this code in your click event : 在您的click事件中添加以下代码:

UIDatePicker *myPicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[myPicker addTarget:self action:@selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:myPicker];

Hope it will help you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM