swiftui - .labelsHidden() 时 View 中的中心选择器

标签 swiftui picker

我正在展示一个带有 WheelDatePickerStyle() 类型的 datePickerStyle 的 SwiftUI DatePicker。它位于一个 Section 中,Section 位于一个 Form 中。当我显示一个部分标题时,我不想显示选择器的标签。但是,在选择时。然而,拾取器刚刚向左移动并留下左侧的一些空间。

我怎样才能让选取器居中,或者确保它占据部分/表单的整个宽度?

DatePicker("Please enter a time", selection: $time, displayedComponents: .hourAndMinute)
    .labelsHidden()
    .datePickerStyle(WheelDatePickerStyle())

最佳答案

DatePicker("Please enter a time", selection: $time, displayedComponents: .hourAndMinute)
    .labelsHidden()
    .datePickerStyle(WheelDatePickerStyle())
    .frame(minWidth: 0, maxWidth: .infinity, alignment: .center)

关于swiftui - .labelsHidden() 时 View 中的中心选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58681361/

相关文章:

ios - 线性颜色渐变到HStack中的项目?

swift - 如何使用 EnvironmentObject 在 SwiftUI 中初始化 State 属性?

ios - SwiftUI:无法向下拖动来关闭 UIImagePickerController

javascript - Bootstrap Datepicker 仅年份不绑定(bind)

javascript - 单击从 JS 动态加载的框后复制到剪贴板

ios - swift/iOS : UIPicker display is not refreshed until tapped after changing the datasource programmatically

ios - 使用 SwiftUI 和 contentMode = .aspectFit 动态裁剪图像

swift - iOS 14 Widget 每天自动刷新

algorithm - 颜色树的颜色选择器

wordpress - 自定义 Wordpress 颜色选择器