I want to do something like the keyboard show/hide so I want to set up picker as a first responder. Is this possible. If not how can i show/hide UIPicker in a view by a button click. On other topic how can i format the DatePicker output, now i get "2011-12-8 23:00 000000"
You could have your UIPicker below your sceen (say, y = 480 for iPhone), and then when you tap your button move it to 480 - picker.frame.size.height so that it shows right above the bottom of your screen.
You can achieve the animated effect by using UIView animations as:
// Pre OS4 way
[UIView beginAnimations:@"animName" context:NULL];
[UIView setAnimationDuration:0.2];
CGRect f = picker.frame;
if (showingPicker) {
f.origin.y = 480;
}
else {
f.origin.y = 480 - picker.frame.size.height;
}
picker.frame = f;
[UIView commitAnimations];
// Post OS4 way - Block based
[UIView animateWithDuration:0.2 animations:^{
if (showingPicker) {
f.origin.y = 480;
}
else {
f.origin.y = 480 - picker.frame.size.height;
}
picker.frame = f;
}
And for the DatePicker output you can use an NSDateFormatter . You can use predefined date and time styles or use setDateFormat:(NSString *)format to specify the format yourself.
After that all you do is call your [formatter stringFromDate:datePicker.date];
您可以在此处找到有关如何使用UIDataPicker的完整源代码。
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.