I have a scroll view just like that.
public var body: some View {
ScrollView {
ZStack {
VStack(spacing: 0) {
BannerView
.frame(height: UIScreen.main.bounds.height * 0.30)
SignInContent
}
}
}
.ignoresSafeArea(.all)
}
Before adding the scrollview
, everything was fine except the screen is not able to scroll. But after I put inside a scrollview. The white area appear. Spacer()
can't help pushing from inside to bottom. Below screenshot, ZStack is highlighted which is inside the scrollview
. I also find a way to change background color of scrollview but can't. The only solution i found yet is to add .padding(.bottom)
to the lowest view of SignInContent
but I don't think it's a proper way.
You have set the height of
BannerView
to 0.3 of the screen height. So I guessSignInContent
has the black background. But if the height ofSignInContent
is not as much as 0.7 of the screen height then the background will run out.A
Spacer
inside aScrollView
will have no effect, so maybe this is why the height ofSignInContent
is less than it was before theScrollView
was put around it. Even settingframe(maxHeight: .infinity)
will have no effect.To fix, you could move the background to the
ScrollView
:Alternatively, you could set the minimum height of
SignInContent
to the remainder of the screen height. Here, it would be better to use aGeometryReader
to read the height of the screen, instead of usingUIScreen.main.bounds
, which is deprecated. However, if the height is increased after the background is applied, then the background won't grow. So you need to do it the other way around and apply the background after increasing the height:You wouldn't have to apply the background again if
SignInContent
was implemented as aZStack
with the background color as one of the layers: