iPhone iOS 4 UITimePicker强制24小时视图
我的应用程序中有一个 UITimePicker,我想用它来选择用户事件后的特定小时数和分钟数。 (例如晚上 7 点后 3 小时 15 分钟)这就是为什么我想以 24 小时格式显示日期,否则用户可能会感到困惑。
有没有办法强制时间选择器显示 24 小时视图,而与区域设置的时钟格式无关?或者我只是选择另一个区域设置?
UIDatePicker *timePicker;
NSDateFormatter *timePickerFormatter;
[self.view addSubview:timePicker];
float tempHeight = timePicker.frame.size.height;
timePicker.frame = CGRectMake(0,150 ,self.view.frame.size.width , tempHeight);
timePicker.hidden = YES;
timePickerFormatter= [[NSDateFormatter alloc]init ];
[timePickerFormatter setDateFormat:@"HH:mm"]; //formats date for processing
谢谢你!
更新:我找到了这样的答案:
timepicker.datePickerMode = UIDatePickerModeCountDownTimer;
这通过显示 0 到 23 小时和 0 到 59 分钟有效地完成了我想要做的事情,无需进一步自定义!抱歉询问 24 小时格式,这就是我要移植的 Android 应用程序正在使用的格式!
I got a UITimePicker in my app, and I want to use it to select a certain number of hours and minutes after a user event. (for example 3 hours 15 minutes after 7PM) This is why I want to show the date in 24 hour format, otherwise the user might get confused.
Is there a way to force the timepicker to show 24 hour view, independent of the clock format for the locale? Or do I just pick another locale?
UIDatePicker *timePicker;
NSDateFormatter *timePickerFormatter;
[self.view addSubview:timePicker];
float tempHeight = timePicker.frame.size.height;
timePicker.frame = CGRectMake(0,150 ,self.view.frame.size.width , tempHeight);
timePicker.hidden = YES;
timePickerFormatter= [[NSDateFormatter alloc]init ];
[timePickerFormatter setDateFormat:@"HH:mm"]; //formats date for processing
Thank you!
Update: I found the answer like this:
timepicker.datePickerMode = UIDatePickerModeCountDownTimer;
This effectively accomplishes what I'm trying to do by displaying 0 to 23 hours and 0 to 59 minutes, no further customization required! Sorry for asking about the 24 hour format, this is what the Android app that I'm porting over was using!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试使用
日历
和UIDatePicker
的locale
属性?这应该是您问题的解决方案,因为正如文档所解释的那样(阅读 UIDatePicker 类参考):
[编辑] 经过进一步调查,似乎
NSLocale
无法覆盖 AM/PM 设置...(我通过...简单地获得了该信息在 Stackoverflow 中搜索!并且您的问题之前已经被提出并回答过很多次)Did you try to use the
calendar
andlocale
properties ofUIDatePicker
?That should be the solution for your problem, because as the documentation explains (read the UIDatePicker class reference):
[EDIT] after further investigation, it seems the
NSLocale
can't override the AM/PM setting… (I had that information by… simply searching here in Stackoverflow! And your question has already been asked and answered many times before)对于可视化,我使用:
您可以使用您自己的语言环境。
对于我使用的 NSDateFormatter:
它不再破坏我的应用程序。
For visualization I use:
You may use your own locale.
And for NSDateFormatter I Use:
It is no longer breaks my applications.