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)
)
我试图.background(Color.red)在许多不同的地方添加,但这是我每次得到的:
在这里做什么?
感谢您的帮助
回答
据我了解您的需求,这是一个解决方案
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)
)