我想更改默认的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))
答案 0 :(得分:0)
我正在这样使用它:
.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))