I wonder why we can set .font
everywhere in SwiftUI.
Why is it not only available in Text?
So I guessed .font modifier changes environment value like CSS.
And I found font property from the list of environment values.
As I thought, we can get the current Font in the hierarchy that set from .font
struct _Text: View {
@Environment(\.font) var font
var body: some View {
print(font?.hashValue)
return Text("Hello").font(font)
}
}
VStack {
_Text()
VStack {
_Text()
VStack {
_Text()
.font(Font.system(size: 11))
}
VStack {
_Text()
.font(Font.system(size: 11))
}
}
.font(Font.system(size: 13))
}
.font(Font.system(size: 16))
Optional(1186401430469500046)
Optional(7474332050221396352)
Optional(-7006744781053325591)
Optional(-7006744781053325591)
But, how about foregroundColor
? I could not find it from EnvironmentValues...