简体   繁体   English

如何从 SwiftUI 中的图形样式 DatePicker 中删除侧边距?

[英]How to remove the side padding from the Graphical Style DatePicker in SwiftUI?

As you can see from the screenshot below, the GraphicalDatePickerStyle date picker by default comes with a side padding on both sides.从下面的屏幕截图中可以看出,默认情况下, GraphicalDatePickerStyle日期选择器在两侧都有一个侧边距。 How to remove the side padding so that the control can align with other controls on the top and bottom.如何移除侧边距,以便控件可以与顶部和底部的其他控件对齐。

Add a padding 0 modifier does not change anything.添加 padding 0 修饰符不会改变任何东西。 One workaround would be to add some offset to the control but we just want to be certain there is no better choice.一种解决方法是向控件添加一些偏移量,但我们只想确定没有更好的选择。

DatePicker("", selection: $actionNotificationTime, displayedComponents: .hourAndMinute)
  .padding(0)

在此处输入图片说明

The same picker inside Settings is perfectly aligned设置中的相同选择器完全对齐

在此处输入图片说明

The workaround with space offset on the control.控件上有空间偏移的解决方法。 Not sure if it would be "perfect" in all screen sizes but at least it is close enough.不确定它是否在所有屏幕尺寸下都是“完美的”,但至少它足够接近。

DatePicker("", selection: $actionNotificationTime, displayedComponents: .hourAndMinute)
    .offset(x: 10)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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