SwiftUI 选择器分隔符 [英] SwiftUI Picker Separators
问题描述
我正在尝试在 MacOS 中创建一个 SwiftUI 选择器,它看起来像 Xcode 或其他 Mac 应用程序中的选择器.更具体地说,我试图在选择器中的元素之间添加分隔线.
Im trying to create a SwiftUI Picker in MacOS that looks like the ones in Xcode or other Mac Apps. To be more specific, I'm trying to add that separator line between the elements in the picker.
像这样:
我尝试了几个选项,但找不到添加这些分隔符的方法.
I had tried several options but I can't find a way to add those separators.
选择器示例代码:
Picker("Pick an option", selection: $selection) {
Text("Option 1").tag(0)
Text("Option 2").tag(1)
Text("Option 3").tag(2)
}
非常感谢您的帮助.
推荐答案
这是可能的技巧(无法命名解决方案,而是解决方法)
Here is possible trick (can't name it solution, rather workaround)
使用 Xcode 11.4/macOS 10.15.5 测试
Tested with Xcode 11.4 / macOS 10.15.5
Picker("Pick an option", selection: $selection) {
Text("Option 1").tag(0)
VStack {Divider().padding(.leading)}
Text("Option 2").tag(1)
Text("Option 3").tag(2)
}
注意:VStack
需要使 Divider
水平,否则由于某些 Apple-ty 原因是垂直的.
Note: VStack
is needed to make Divider
horizontal, otherwise it is for some Apple-ty reason is vertical.
这篇关于SwiftUI 选择器分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!