How to change TipKit action button's color in SwiftUI?

186 views Asked by At

As shown in code below. I wanna to figure out a way to modify the color of the action button. I know we can change color of title and message by foregroundcolor. But not the action button's theme.

struct PasswordTip: Tip {
var title: Text {
    Text("Need Help?")
}
var message: Text? {
    Text("Do you need help logging in to your account?")
}
var image: Image? {
    Image(systemName: "lock.shield")
}
var actions: [Action] {
    Action(id: "faq", title: "View our FAQ")
}

}

2

There are 2 answers

0
son On

Action initialize can take content as a Label

var actions: [Action] {
    Action(id: "faq") {
        //TODO:
    } _: {
        Text("View your FAQ")
            .foregroundStyle(.red)
    }
}

enter image description here

0
Jorge Paiz On

I suggest another approach. Use "TipViewStyle", something like this:

struct ErrorTipStyle: TipViewStyle {
  func makeBody(configuration: Configuration) -> some View {
    VStack {
             ...
             ForEach(configuration.actions) { action in
                Button(action: action.handler) {
                    action.label()
                        .foregroundColor(.white)
                }
                .padding()
             }
      }
   } 
}