swiftui-.hourandminute仅显示“ 00”和&quot“ 30'分钟
我希望我的头衔足够解释。我有一个小时的时间选择器,每分钟都会单独显示。我想要的是仅显示“ 00”和“ 30”分钟。这是可以实现的吗?
我在时间选择器中使用的代码:
DatePicker("", selection: $selectedStartHour, displayedComponents: .hourAndMinute)
.datePickerStyle(CompactDatePickerStyle())
.labelsHidden()
.clipped()
I hope my title is self explanatory enough. I have an hours and minutes time picker, where every minute is shown individually. What I want is to only show the "00" and "30" minutes. Is this achievable?
The code I use for the time picker:
DatePicker("", selection: $selectedStartHour, displayedComponents: .hourAndMinute)
.datePickerStyle(CompactDatePickerStyle())
.labelsHidden()
.clipped()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发表的评论是错误的。当然,您可以使用一个插件的代码来执行此操作:
问题是,整个应用程序中的所有时间选择器现在都将以30分钟的增量增量。为了减轻这一点,您使用.onappear和.ondisappear如下:
现在,当您的视图出现时,选择器将设置为30分钟的增量。当视图消失时,它将设置回1分钟增量的默认值。
现在,您可以轻松地控制按观看次数显示的时间增量。
The comment posted is wrong. You can of course do this with a one line piece of code:
The issue is that now all of your time pickers throughout your entire app will be in 30 minute increments. To alleviate this, you use .onAppear and .onDisappear as follows:
Now, when your view appears the picker will be set to 30 minute increments. When the view disappears, it will be set back to the default of 1 minute increments.
Now you can easily control what time increment is displayed on a per view basis.