Home > Enterprise >  SwiftUI: Can you have a different background color for the top and bottom of a ScrollView?
SwiftUI: Can you have a different background color for the top and bottom of a ScrollView?

Time:02-19

Is it possible to have different background color for the top and bottom of a ScrollView?

For example, I when I scroll upwards, I'd like the green background of the ScrollView to be blue, and when I scroll downwards I'd like the green background of the ScrollView to be red:

enter image description here

CodePudding user response:

Yes, replace your background with this:

.background(VStack(spacing: .zero) { Color.blue; Color.red })
  • Related