iosswiftswiftuiwidgetios17

swiftui widget button intent has a default background, how to remove it


I'm build a widget for a iOS17 app, and below is widget' button code

var body: some View {

    if #available(iOS 17.0, *) {
        Button(intent: TodoCheckInIntent(todoId: todo.id)) {
            Text("hello")
        }
        .frame(width: 65, height: 21)
    } else {
        todoSubView
    }
}

After run on ios17, it's like this. The button has a wired blue background. My Question is how to remove the wired blue background.

Demo

Thanks for any answer

I have use .padding(0) to the Button, but don't have any effects


Solution

  • Thats because of the default button style. You should use .buttonStyle(.plain) on the button:

    Button(intent: TodoCheckInIntent(todoId: todo.id)) {
        Text("hello")
    }
    .frame(width: 65, height: 21)
    .buttonStyle(.plain) // 👈 Here