Swift background修飾子を使ってScrollViewの背景色を設定するサンプル
環境
Swift version 5.2.3 (swift-5.2.3-RELEASE)
Ubuntu 20.04.2 LTS
構文
ScrollView {
//Viewコード
}
.background(color) //背景色を指定する
ScrollViewの背景色を設定するには、background修飾子を使います。
background修飾子の引数に背景色を指定します。
使用例
struct ContentView: View {
var body: some View {
VStack {
ScrollView {
ForEach(0..<5) { index in
Text("Test \(index)")
.foregroundColor(.white)
.padding()
}
}
.background(Color.green)
}
}
}
struct ContentView: View {
var body: some View {
VStack {
ScrollView {
ForEach(0..<5) { index in
Text("Test \(index)")
.foregroundColor(.white)
.padding()
}
}
.background(Color.green)
}
}
}
struct ContentView: View { var body: some View { VStack { ScrollView { ForEach(0..<5) { index in Text("Test \(index)") .foregroundColor(.white) .padding() } } .background(Color.green) } } }