SwiftUI 特定边的边框

Sar*_*ith 3 ios swiftui

我使用下面的代码添加了所有边的边框SwiftUI

Rectangle()
 .overlay(Rectangle()
 .fill(Color.white).padding(2))
 .foregroundColor(Color.red)
Run Code Online (Sandbox Code Playgroud)

如何为特定边添加边框Rectangle

Asp*_*eri 5

这种情况下的解决方案是使用明确指定的边缘来应用填充

Rectangle()
    .overlay(Rectangle()
        .fill(Color.white).padding([.leading, .trailing], 2))  // << here !!
    .foregroundColor(Color.red)
Run Code Online (Sandbox Code Playgroud)