【问题标题】:SwiftUI MacOs TabsSwiftUI MacOs 选项卡
【发布时间】:2021-01-20 21:43:42
【问题描述】:

我正在 MacOS 中为自己制作一个小助手应用程序,全部使用 Swift + SwiftUI(新手),但找不到执行这些选项卡的方法:

是否有一种特定的方法可以仅使用 SwiftUi 创建该接口,也许是某种库?我确实搜索了“SwiftUI 选项卡”,但只找到了 iOs 选项卡。

【问题讨论】:

    标签: swift swiftui


    【解决方案1】:

    对于 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")
            }
    }
    

    【讨论】:

      【解决方案2】:
      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()
              }
          }
      }
      

      【讨论】:

        【解决方案3】:

        不用担心,

        MacOs 10.15 及更高版本默认使用:https://developer.apple.com/documentation/swiftui/tabview

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-05-08
          • 2020-07-12
          • 1970-01-01
          • 2023-03-28
          • 2020-10-10
          • 1970-01-01
          • 1970-01-01
          • 2020-02-09
          相关资源
          最近更新 更多