相关疑难解决方法(0)

在 SwiftUI 中更改选择器的导航标题

当用户选择某些选项时,我想设置导航标题 Picker

这是我的选择模型:

enum AppIcon: CaseIterable, Identifiable {

    var id: Self {
        return self
    }

    case `default`
    case ethereum
    case litecoin

    var name: String {
        switch self {
        case .default:
            return "Bitcoin"
        case .ethereum:
            return "Ethereum"
        case .litecoin:
            return "Litecoin"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的观点

struct ContentView: View {
    @State var icon: AppIcon = .default
    var body: some View {
        NavigationView {
            Form {
                Section {
                    Picker(selection: $icon, label: Text("Icon")) {
                        ForEach(AppIcon.allCases) { icon in
                            Text(icon.name).tag(icon)
                        }
                    }
                }
            }
            .navigationBarTitle("Appearance") …
Run Code Online (Sandbox Code Playgroud)

picker ios swift swiftui

12
推荐指数
1
解决办法
3768
查看次数

标签 统计

ios ×1

picker ×1

swift ×1

swiftui ×1