ios - SwiftUI:有没有办法创建一个单选列表(比如在 iOS 设置中)?
问题描述
我目前正在使用 Swift UI 构建我的第一个 iOS 应用程序,我想知道 Swift UI 中是否有任何标准方式允许在列表中进行单选。就像 iOS 设置中的情况一样(见下面的截图)。
提前感谢您的帮助!
解决方案
同时通过 hackingwithswift.com 上的示例代码找到了答案
struct ContentView: View {
var strengths = ["Mild", "Medium", "Mature"]
@State private var selectedStrength = 0
var body: some View {
NavigationView {
Form {
Section {
Picker(selection: $selectedStrength, label: Text("Strength")) {
ForEach(0 ..< strengths.count) {
Text(self.strengths[$0])
}
}
}
}.navigationBarTitle("Select your cheese")
}
}
}
推荐阅读
- scala - Scala 隐式转换的问题
- excel - 在 Excel 中将 API 调用转换为表格
- python - defaultdict(lambda: set()) 如何添加
- mysql - 使用条件批量更新 MySQL 值
- javascript - 检索 Safari 扩展程序创建的数据
- ios - 消息“[ProcessSuspension] 0x282ead7c0-processassertion () Unable to acquire assertion for process with PID 0”
- ios - 创建静态下拉菜单
- linux - 如何在 centOS 7 上找到 binutils 的安装位置?
- c++ - 如何以二进制格式将 C++ 对象的 std::vector 保存到磁盘?
- javascript - 将 URL 搜索参数解析为具有编码 url 的对象数组