菜单标题问题和不透明度降低 [英] Issue with Menu title and decreased opacity

查看:41
本文介绍了菜单标题问题和不透明度降低的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 SwiftUI 中使用新的 Menu,但不幸的是,有一个我无法解决的问题.选择 Menu 的一个值后,Menutitle 看起来像这样:

I want to use the new Menu with SwiftUI but unfortunately there is one issue which I can't solve. After selecting one value of the Menu the Menutitle looks like so:

但是我不希望标题降低它的不透明度.我怎样才能做到这一点?

However I don't want the title to decrease it's opacity. How can I achieve this?

这是我的代码:

struct ContentView: View {
    @State private var selectionVariable = 0
    
    let sampleDict = [0: "Sample Title 1", 1: "Sample Title 2"]
    
    var body: some View {
        Menu {
            Picker(selection: $selectionVariable, label: Text("")) {
                ForEach(sampleDict.sorted(by: <), id: \.key) { base, name in
                    Text(name)
                }
            }
        }
        label: {
            Text("Eingaben im \(sampleDict[selectionVariable] ?? "")")
        }
    }
}

推荐答案

我会说它看起来像一个错误,无论如何值得向 Apple 提交反馈.

I'd say it looks like a bug, anyway worth submitting feedback to Apple.

这里是经过测试的解决方法(Xcode 12.1/iOS 14.1)

Here is tested workaround (Xcode 12.1 / iOS 14.1)

    label: {
        Text("Eingaben im \(sampleDict[selectionVariable] ?? "")")
                .id(selectionVariable)    // << this one !!
    }

这篇关于菜单标题问题和不透明度降低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆