我为选择性别创建了一个细分选择器,在该细分选择器中,我必须为男性选择一个,为女性选择另一个。选择器工作正常但使用选择器设置标题 it\xe2\x80\x99s 未显示。我设置了标题“选择性别”,但它没有在选取器上显示为标题。
\n\nstruct 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 }\nRun Code Online (Sandbox Code Playgroud)\n\n截屏:
\n\n\n我点击选择器,它将打开屏幕,屏幕上显示元素列表,我们可以添加搜索栏吗?
我实现了国家/地区选择器,在国家/地区列表中显示国家/地区名称和国家/地区代码,以便在该列表屏幕上添加搜索栏轻松查找国家/地区。
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)
通过运行上面的代码,它将打开一个像上面屏幕一样的国家/地区列表。
在上面的屏幕上(国家/地区列表)。
如何添加搜索栏来过滤国家/地区数据?
我想要一个无法擦除的“+”号文本字段。用户应该能够在它之后输入值,如果他按下退格键,它应该只擦除他输入的值。当我写任何其他数字时,它会自动在输入值的开头添加一个“+”。
例如:- 我想在文本字段中添加国家/地区代码,因此,一旦用户开始输入国家/地区代码,“+”就会自动添加到字段的开头。
swiftui ×3
picker ×1
prefix ×1
searchbar ×1
segment ×1
swift ×1
swiftui-list ×1
textfield ×1
title ×1
validation ×1