どうも、ちょげ(@chogetarou)です。
特定のViewにRoundedRectangleを被せる方法を紹介します。
方法

特定のViewにRoundedRectangleを被せるには、overlay修飾子を使います。
まず、Viewにoverlay修飾子を付与します。
そして、overlay修飾子の引数に「RoundedRectangle」を指定します。
SampleView()
.overlay(
RoundedRectangle()
)
overlay修飾子を使うことで、特定のViewにRoundedRectangleを被せることが出来ます。
使用例

struct ContentView: View {
var body: some View {
VStack {
Text("Hello, SwiftUI")
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(Color.red, lineWidth: 2)
.frame(width: 200, height: 50)
)
}
}
}
コメント