SwiftUIでViewの上にViewを重ねる
SwiftUIでViewの上にViewを重ねる方法です。
ContentView.swift
import SwiftUI
struct ContentView: View {
var body: some View {
Image(.icon)
.resizable()
.frame(width: 200, height: 200)
.overlay(
Text("@takoikatakotako")
.foregroundColor(Color.white)
.font(Font.system(size: 20).bold())
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.background(Color.black)
.opacity(0.5)
)
}
}
#Preview {
ContentView()
}
