【问题标题】:SwiftUI: apply background color to rounded rectangleSwiftUI:将背景颜色应用于圆角矩形
【发布时间】:2020-12-08 15:41:32
【问题描述】:

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

到目前为止我写了这个:

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),但这是我每次都得到的:

在这里做什么?

感谢您的帮助

【问题讨论】:

    标签: ios swiftui


    【解决方案1】:

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

    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)
    )
    

    【讨论】:

    • 完美,谢谢!我仍然不习惯将颜色以外的其他东西设置为背景...
    猜你喜欢
    • 2011-12-30
    • 1970-01-01
    • 2013-04-28
    • 1970-01-01
    • 2020-03-27
    • 1970-01-01
    • 1970-01-01
    • 2018-05-27
    • 1970-01-01
    相关资源
    最近更新 更多