具有SegmentPickerStyle()的选择器在SwiftUI中未显示选择器标题

问题描述 投票:0回答:1

我为该细分选择器中的选定性别创建了一个细分选择器,我必须为男性选择一个,为女性选择另一个。选择器工作正常,但未显示选择器上的标题。我设置标题选择性别,但在选择器上未显示为标题。

struct ManagerChildrenView: View {

        //MARK: Properties
        @State var selectedGender = 0
        let genders = ["Male", "Female"]

        var body: some View {

            Form{
                Section{
                    Picker("Select Gender", selection: $selectedGender) {

                        ForEach(0..<genders.count) { index in
                            Text(self.genders[index]).tag(index).font(.title)
                        }
                    }.pickerStyle(SegmentedPickerStyle())
                }
            }
        }
    }

感谢“![在此处输入图像描述”] 1

swiftui title picker segment
1个回答
0
投票

标签不用于SegmentedPickerStyle。相反,您可以使用以下方法]

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9Mdmswdy5wbmcifQ==” alt =“在此处输入图像描述”>

HStack {
    Text("Select Gender")
    Picker("", selection: $selectedGender) {

        ForEach(0..<genders.count) { index in
            Text(self.genders[index]).tag(index).font(.title)
        }
    }.pickerStyle(SegmentedPickerStyle())
}
© www.soinside.com 2019 - 2024. All rights reserved.