HomeiOS Developmentios - SwiftUI: Button Fashion does not work when menu is offered...

ios – SwiftUI: Button Fashion does not work when menu is offered after tapping on a button


In my app, I want to add a performance the place when a button is tapped, menu ought to be offered with an inventory of things.

All that is working wonderful besides the textual content/foreground coloration of the button occurs to be similar because the background coloration of the view on which button is positioned. In my pattern code under it occurs to be white coloration. When menu is offered, appears to be like like iOS fades or reduces opacity of button’s background and foreground and due to this the textual content on the button is just not seen.

I want have the button textual content seen in some coloration and therefore I added button fashion, but it surely does not work when menu is offered. It really works on common button faucets, however not with menu. The best way to change the button foreground/background when menu is offered? I’m utilizing iOS 16+.

Code:

import SwiftUI
import Basis

struct ContentView: View {
    @State non-public var showSignInOptionsView = false
    var physique: some View {
        VStack {
            Menu {
                Button {} label: {
                    Textual content("Menu 1")
                }
                Button {} label: {
                    Textual content("Menu 2")
                }
                Button {} label: {
                    Textual content("Menu 3")
                }
            } label: {
                Button { showSignInOptionsView.toggle() } label: {
                    Textual content("Signal In").body(maxWidth: .infinity).contentShape(Rectangle())
                }
                .buttonStyle(SignInButtonStyle())
            }

// Be aware: button fashion works on this because it's common button. Uncomment to check.
//            Button { showSignInOptionsView.toggle() } label: {
//                Textual content("Signal In - Common Button").body(maxWidth: .infinity).contentShape(Rectangle())
//            }
//            .buttonStyle(SignInButtonStyle())
        }
    }
}

non-public struct SignInButtonStyle: ButtonStyle {

    func makeBody(configuration: Self.Configuration) -> some View {
        configuration.label
        .font(.physique.daring())
        .foregroundColor(configuration.isPressed ? .black : .white)
        .body(width: UIScreen.predominant.bounds.width - 50.0, peak: 30.0)
        .padding(10.0)
        .background(configuration.isPressed ? .grey : .blue)
        .cornerRadius(10.0)
    }
}

Screenshots: I want to have button textual content clearly seen in the appropriate screenshot i.e. when menu is open.

enter image description here
enter image description here

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments