你如何在 WatchOS 中用背景视图填充整个按钮区域?

How do you fill entire Button area with background View in WatchOS?

我正在尝试让我的背景视图跨越 Apple Watch 外形规格上 Button 的整个区域。

struct SurveyView: View {

var body: some View {
    Button(action: {
        print("Test tapped.")
    }) {
        HStack {
            Text("Test")
                .fontWeight(.semibold)
        }
        .frame(minWidth: 0, maxWidth: .infinity)
        .padding()
        .foregroundColor(.white)
        .background(LinearGradient(gradient: Gradient(colors: [.green, .blue]), startPoint: .leading, endPoint: .trailing))


     }
   }
}

如何让背景横跨整个Button?

更新: 原来我的问题也与列表视图有关。设置掩码并不能完全解决它。

struct SurveyView: View {

var body: some View {
    List() {
        Button(action: {
            print("Test tapped.")
        }) {
            Text("Test")
                .fontWeight(.semibold)
        }
        .background(Color.orange)


        .mask(RoundedRectangle(cornerRadius: 24))
        }
    }
}

我将按以下方式执行此操作:

Button(action: {
    print("Test tapped.")
}) {
    Text("Test")
        .fontWeight(.semibold)
        .padding()
        .foregroundColor(.white)
}
.background(LinearGradient(gradient: Gradient(colors: [.green, .blue]), startPoint: .leading, endPoint: .trailing))
.mask(RoundedRectangle(cornerRadius: 24))

更新: 列表案例

var body: some View {
    List() {
        Button(action: {
            print("Test tapped.")
        }) {
            Text("Test")
                .fontWeight(.semibold)
                .padding()
        }
        .background(Color.orange)
        .mask(RoundedRectangle(cornerRadius: 24))
        .listRowPlatterColor(Color.clear)
    }
}