SwiftUI - 胶囊填充直到 StrokeBorder

Swi*_*kie 6 background border swiftui

我试图填充胶囊式的描边边框,但不幸的是它填充了矩形。见下图:

在此输入图像描述

有什么想法可以让它只填充到笔画边框吗?我想使用该字段作为搜索框,这就是为什么我想在其中使用文本字段。

这是我的代码:

struct ContentView: View {
    
    var body: some View {
        
        HStack{
            TextField("Search", text: .constant(""))
        }
        .padding()
        .frame(maxWidth:300)
        .background(
            Capsule()
                .strokeBorder(Color.black,lineWidth: 0.8)
                .background(Color.blue)
                .clipped()
        )
    }
}
Run Code Online (Sandbox Code Playgroud)

非常感谢!

Tim*_*ner 11

我想这就是你所追求的。

struct ContentView: View {

var body: some View {
    
    HStack{
        TextField("Search", text: .constant(""))
    }
    .padding()
    .frame(maxWidth:300)
    .background(
        Capsule()
            .strokeBorder(Color.black,lineWidth: 0.8)
            .background(Color.blue)
            .clipped()
    )
    .clipShape(Capsule())
    }
}
Run Code Online (Sandbox Code Playgroud)

带胶囊边框的 HStack 的 Xcode 预览