SwiftUI:将背景颜色应用于圆角矩形

Ano*_*ude 6 ios swiftui

我想创建一个带有边框和背景颜色的圆角矩形视图的按钮。

到目前为止我写了这个:

Button(action: {
}, label: {
    Text("TAP ME")
        .foregroundColor(Color.blue)
})
.frame(height: 50)
.frame(maxWidth: .infinity)
.overlay(
    RoundedRectangle(cornerRadius: 50, style: .continuous)
        .strokeBorder(Color.blue, lineWidth: 1)                
)
Run Code Online (Sandbox Code Playgroud)

我试图.background(Color.red)在许多不同的地方添加,但这是我每次得到的:

在此处输入图片说明

在这里做什么?

感谢您的帮助

Asp*_*eri 10

据我了解您的需求,这是一个解决方案

演示

Button(action: {
}, label: {
    Text("TAP ME")
        .foregroundColor(Color.blue)
})
.frame(height: 50)
.frame(maxWidth: .infinity)
.background(
    RoundedRectangle(cornerRadius: 50, style: .continuous).fill(Color.red)
)
.overlay(
    RoundedRectangle(cornerRadius: 50, style: .continuous)
        .strokeBorder(Color.blue, lineWidth: 1)
)
Run Code Online (Sandbox Code Playgroud)