【问题标题】:iOS 14 menu picker style's label becomes dim sometimes when changingiOS 14 菜单选择器样式的标签在更改时有时会变暗
【发布时间】:2020-10-31 12:43:02
【问题描述】:

我的SwiftUI View 中有一个Picker 和新的MenuPickerStyle

如您所见,选择器的标签与选项相同,从一个选项更改为另一个选项时会变暗。

看起来它是不可点击的,但是当点击它时它会完成所需的工作。

这是我的代码。这只是一个非常简单的选择器实现。

struct MenuPicker: View {
    
    @State var selection: String = "one"
    
    var array: [String] = ["one", "two", "three", "four", "five"]

    var body: some View {
        Picker(selection: $selection, label: Text(selection).frame(width: 100), content: {
            ForEach(array, id: \.self, content: { word in
                Text(word).tag(word)
            })
        })
        .pickerStyle(MenuPickerStyle())
        .padding()
        .background(Color(.systemBackground).edgesIgnoringSafeArea(.all))
        .cornerRadius(5)
    }
}

struct ContentView: View {
    
    var body: some View {
        ZStack {
            Color.gray
            MenuPicker()
        }
    }
}

【问题讨论】:

    标签: ios swift swiftui ios14


    【解决方案1】:

    看起来这是一个错误:

    public init(selection: Binding<SelectionValue>, label: Label, @ViewBuilder content: () -> Content)
    

    您可以尝试将其替换为:

    public init(_ titleKey: LocalizedStringKey, selection: Binding<SelectionValue>, @ViewBuilder content: () -> Content)
    

    这是一种解决方法(您只能使用String 作为标签):

    Picker(selection, selection: $selection) {
        ForEach(array, id: \.self) { word in
            Text(word).tag(word)
        }
    }
    .frame(width: 100)
    .animation(nil)
    .pickerStyle(MenuPickerStyle())
    

    【讨论】:

    • 伟大的发现!我正在为那个初始化程序提交一个雷达。
    • 不幸的是,其他初始化程序或解决方法都不适用于我,但至少我们可以确认这是一个错误。 @Imthath 你能把雷达链接发给我吗?
    • @benpva16 我不知道如何分享雷达链接。这是我提交的问题的反馈助手 ID - FB8888712。
    猜你喜欢
    • 2021-04-05
    • 2021-08-26
    • 1970-01-01
    • 1970-01-01
    • 2021-02-08
    • 1970-01-01
    • 2013-11-27
    • 1970-01-01
    • 2011-11-05
    相关资源
    最近更新 更多