SwiftUIでViewの上にViewを重ねる
SwiftUIでViewの上にViewを重ねる方法です。 Imageの上に半透明に黒いTextを重ねています。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
Image("icon") | |
.resizable() | |
.frame(width: 200, height: 200) | |
.overlay( | |
Text("Snorlax") | |
.foregroundColor(Color.white) | |
.font(Font.system(size: 20).bold()) | |
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) | |
.background(Color.black) | |
.opacity(0.5) | |
) | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} | |