I want to set the background color for "Sebastian’s Favorite Stuff" to encompass the entire area. Currently it looks like this and I want to cover the white spaces.
My Code is as follows:
var body: some View {
VStack{
GridRow{
Text("SEBASTIAN'S FAVORITE STUFF")
.lineLimit(1)
.padding(10)
.font(.system(size: 500))
.minimumScaleFactor(0.01)
.colorInvert()
}
.background(Color(red: 0.18 , green: 0.59 , blue: 0.65 ))
HStack{
ScrollView{
Grid{
What do I need to adjust so it fills the area and not just the text background?
2
Answers
If you chain
.frame(maxWidth: .infinity)
on theText
as the last modifier, the background color should extend to the left and right edges.A
GridRow
is expected to be a child of aGrid
. So in this case, I wouldn’t use aGridRow
and just useText
by itself.Then, all you need to do is force the text to use the full width. Since the background will touch the edges of the safe area, it will extend into the safe area too. This is because you are using
background(_:ignoresSafeAreaEdges:)
(with round parentheses). The default parameter forignoresSafeAreaEdges
isEdge.Set.all
.Like this:
If you want to fill the whole screen background then you could move the background up a level and put it behind the
VStack
instead. ThemaxWidth
is no longer needed on theText
. It is not needed on theVStack
either, because theScrollView
will force theVStack
to fill all the space available (aScrollView
is greedy).If that still leaves some gaps then you need to look at the next parent, and so on.