swiftui 小部件按钮意图有默认背景,如何删除它

问题描述 投票:0回答:1

我正在为 iOS17 应用程序构建一个小部件,下面是小部件的按钮代码

var body: some View {

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

在ios17上运行后是这样的。该按钮具有有线蓝色背景。 我的问题是如何删除有线蓝色背景。

Demo

感谢您的回答

我对按钮使用了

.padding(0)
,但没有任何效果

ios swift swiftui widget ios17
1个回答
0
投票

那是因为默认的按钮样式。您应该在按钮上使用

.buttonStyle(.plain)

Button(intent: TodoCheckInIntent(todoId: todo.id)) {
    Text("hello")
}
.frame(width: 65, height: 21)
.buttonStyle(.plain) // 👈 Here
© www.soinside.com 2019 - 2024. All rights reserved.