Border for Specific Sides SwiftUI

Viewed 949

I have added the borders for all sides using code below in SwiftUI

Rectangle()
 .overlay(Rectangle()
 .fill(Color.white).padding(2))
 .foregroundColor(Color.red)

How to add a border for specific sides of Rectangle?

1 Answers

The solution in this case is to use explicitly specified edges to which padding is applied

Rectangle()
    .overlay(Rectangle()
        .fill(Color.white).padding([.leading, .trailing], 2))  // << here !!
    .foregroundColor(Color.red)
Related