Example 1:
struct ContentView: View {
var body: some View {
Image("skill-img1")
.resizable()
.scaledToFit()
.overlay(
Text("Mac OS Catalina")
.foregroundColor(.gray)
.font(.largeTitle)
,alignment: .bottomTrailing)
}
}
Example 2: show disabled transparent black cover
Text("Good")
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.background(Color.orange)
.edgesIgnoringSafeArea(.all)
.overlay(Rectangle()
.fill(Color.black.opacity(0.6))
.edgesIgnoringSafeArea(.all)
)
Example 3: optional overlay
Text("good")
.overlay(JiJingListOverlayView(showOverlay: $model.showSideView))
struct JiJingListOverlayView: View {
@Binding var showOverlay: Bool
@ViewBuilder
var body: some View {
if showOverlay {
Rectangle()
.fill(Color.black.opacity(0.3))
.edgesIgnoringSafeArea(.all)
} else {
EmptyView()
}
}
}
Example 4: one side of border
.overlay(Rectangle().frame(width: nil, height: 1, alignment: .top).foregroundColor(Color.gray), alignment: .top)