【发布时间】:2021-01-20 21:43:42
【问题描述】:
我正在 MacOS 中为自己制作一个小助手应用程序,全部使用 Swift + SwiftUI(新手),但找不到执行这些选项卡的方法:
是否有一种特定的方法可以仅使用 SwiftUi 创建该接口,也许是某种库?我确实搜索了“SwiftUI 选项卡”,但只找到了 iOs 选项卡。
【问题讨论】:
我正在 MacOS 中为自己制作一个小助手应用程序,全部使用 Swift + SwiftUI(新手),但找不到执行这些选项卡的方法:
是否有一种特定的方法可以仅使用 SwiftUi 创建该接口,也许是某种库?我确实搜索了“SwiftUI 选项卡”,但只找到了 iOs 选项卡。
【问题讨论】:
对于 MacO,您也应该使用 TabView
TabView {
Text("This is the first tab") //Replace this with the view content for the first tab
.tabItem {
Text("Sound Effects")
}
Text("This is the second tab") //same here
.tabItem {
Text("Output")
}
Text("This is the third tab") //and here
.tabItem {
Text("Input")
}
}
【讨论】:
struct ContentView: View {
@State var selectorIndex = 0
var body: some View {
VStack {
Picker("Numbers", selection: $selectorIndex) {
ForEach(0 ..< 3) { index in
Text("\(index)")
.tag(index)
}
}
.pickerStyle(SegmentedPickerStyle())
Text("\(selectorIndex)")
.font(.title)
Spacer()
}
}
}
【讨论】:
不用担心,
MacOs 10.15 及更高版本默认使用:https://developer.apple.com/documentation/swiftui/tabview
【讨论】: