SwiftUI has its own color pallete separate from UIKit
. If you want to access UIKit
colors you can do so like thi.
.background(Color(.systemFill))
Note how only the text gets the background color.
ZStack {
Text("Your content")
}
.background(Color.red)
Same result as this.
ZStack {
Text("Your content")
.background(Color.red)
}
If you want to fill in the whole area behind the text, you should place the color into the ZStack
. Treat it as a whole view all by itself.
ZStack {
Color.red
Text("Your content")
}
Color.red
is a view in it's own right, which is why ic can be sued for shapes and text. It automatically takes up all the space, but you can also use the frame()
modifier too.
If you want to ignore safeArea.
ZStack {
Color.red.edgesIgnoringSafeArea(.all)
Text("Your content")
}
let appColor = Color(red: 128/255, green: 165/255, blue: 117/255)