小编Rav*_*ati的帖子

使用 SegmentPickerStyle() 的选取器不会在 SwiftUI 中显示选取器标题

我为选择性别创建了一个细分选择器,在该细分选择器中,我必须为男性选择一个,为女性选择另一个。选择器工作正常但使用选择器设置标题 it\xe2\x80\x99s 未显示。我设置了标题“选择性别”,但它没有在选取器上显示为标题。

\n\n
struct ManagerChildrenView: View {\n\n        //MARK: Properties\n        @State var selectedGender = 0\n        let genders = ["Male", "Female"]\n\n        var body: some View {\n\n            Form{\n                Section{\n                    Picker("Select Gender", selection: $selectedGender) {\n\n                        ForEach(0..<genders.count) { index in\n                            Text(self.genders[index]).tag(index).font(.title)\n                        }\n                    }.pickerStyle(SegmentedPickerStyle())\n                }\n            }\n        }\n    }\n
Run Code Online (Sandbox Code Playgroud)\n\n

截屏:

\n\n

在此输入图像描述

\n

title picker segment swiftui

7
推荐指数
1
解决办法
2578
查看次数

在选择器列表 SwiftUI 上添加搜索栏

我点击选择器,它将打开屏幕,屏幕上显示元素列表,我们可以添加搜索栏吗?

我实现了国家/地区选择器,在国家/地区列表中显示国家/地区名称和国家/地区代码,以便在该列表屏幕上添加搜索栏轻松查找国家/地区。

struct ContentView: View {

    //All Country get from the plist with country Code and Coutnry Name.
    let countyList = Country().getAllCountyInfo()

    // Selected Country
    @State private var selectedCountry = 0

    var body: some View {


        NavigationView {
            Form {
                Picker(selection: $selectedCountry, label: Text("Country")) {

                    ForEach(countyList) { country in

                        HStack{
                            Text(country.countryName ?? "")
                            Spacer()
                            Text(country.countryCode ?? "")
                        }
                    }
                }
            }
            .navigationBarTitle("Select country picker")
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

通过运行上面的代码,它将打开一个像上面屏幕一样的国家/地区列表。

在上面的屏幕上(国家/地区列表)。

如何添加搜索栏来过滤国家/地区数据?

country-codes searchbar swift swiftui swiftui-list

6
推荐指数
1
解决办法
6478
查看次数

在 SwiftUI 中为 TextField 添加前缀

我想要一个无法擦除的“+”号文本字段。用户应该能够在它之后输入值,如果他按下退格键,它应该只擦除他输入的值。当我写任何其他数字时,它会自动在输入值的开头添加一个“+”。

例如:- 我想在文本字段中添加国家/地区代码,因此,一旦用户开始输入国家/地区代码,“+”就会自动添加到字段的开头。

validation country-codes prefix textfield swiftui

5
推荐指数
2
解决办法
1614
查看次数