1
Menu {
    Button("Duplicate", action: {})
    Button("Rename", action: {})
    Button("Delete…", action: {})
  }
  label: {
    Button("Glass Button", action:{}).glassEffect()
}

On using above snippet, when menu is dismissed it shows rectangular artifact instead of smoothly transitioning to the glass effect. Is this the correct way to use glassEffect buttons with a Menu?

Rectangle artifact appears when menu is dismissed

1
  • Have a look at Apply and configure Liquid Glass effects. It says "Use the glassEffect(_:in:) modifier to add Liquid Glass effects to a view. By default, the modifier uses the regular variant of Glass and applies the given effect within a Capsule shape behind the view’s content". Commented Oct 1 at 2:14

1 Answer 1

1

A Menu is already a Button that, when tapped, opens a menu. It does not need another Button as its label. That button's action would not be triggered in any case.

You should just use a Text as the menu's label, and change the menu's (built-in) button to use the .glass style.

Menu("Glass Button") {
    Button("Duplicate", action: {})
    Button("Rename", action: {})
    Button("Delete…", action: {})
}
.buttonStyle(.glass)

If you still want the button's text to be coloured with the app's accent color, you can do

Menu {
    Button("Duplicate", action: {})
    Button("Rename", action: {})
    Button("Delete…", action: {})
}
label: {
    Text("Glass Button").foregroundStyle(Color.accentColor)
}
.buttonStyle(.glass)

But note that this is not how glass buttons are designed to look.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.