简体   繁体   中英

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. When a date is selected, date picker should disappear and the selected date should be shown in my UILabel.

How can I do this? I am using Xcode 5. I want to do this for 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/

//edit: I skimmed through the tutorial, this is not a good example.

Use UIDatePicker is better.

Add this code in your click event :

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

Hope it will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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