gpt4 book ai didi

macos - 如何在 SwiftUI 中获取默认按钮颜色?

转载 作者:行者123 更新时间:2023-12-04 17:31:34 25 4
gpt4 key购买 nike

我想更改默认的 MenuButton 样式。我想使用默认按钮颜色而不是 Color.gray

MenuButton("Actions") {
Button(action: {
}, label: { Text("Action 1") })
Button(action: {
}, label: { Text("Action 2") })
}
.menuButtonStyle(BorderlessButtonMenuButtonStyle())
.background(RoundedRectangle(cornerRadius: 5).foregroundColor(Color.gray))

我尝试改变默认样式看起来像 enter image description here

按钮样式 enter image description here

最佳答案

我是这样使用它的:

        .foregroundColor(.accentColor)
.background(Color(UIColor.systemBackground))

创建样式如下:

struct MainButtonStyle: PrimitiveButtonStyle {
let minWidth: CGFloat
let minHeight: CGFloat

func makeBody(configuration: Self.Configuration) -> some View {
Button(configuration)
.frame(minWidth: minWidth, minHeight: minHeight)
.font(.body)
.foregroundColor(.accentColor)
.background(Color(UIColor.systemBackground))
.buttonStyle(BorderlessButtonStyle())
.cornerRadius(5)
}
}

用例:

    Button(action: { }, label: {
Image(systemName: "map")
})
.buttonStyle(MainButtonStyle(minWidth: 30, minHeight: 30))

关于macos - 如何在 SwiftUI 中获取默认按钮颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59224426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com