Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
346 views
in Technique[技术] by (71.8m points)

SwiftUI: how to keep font colours in top edge area?

I use a custom black background in an app so I am using this code to ignore the SafeArea

   var body: some View {
        ZStack {
            Color.backgroundColor
//                vertical  only for bg  color but how do I keep
//                the color of the font ?
                
               .edgesIgnoringSafeArea(.vertical)

all is fine in dark mode

enter image description here

but in light mode the time, antenna and battery are invisible enter image description here

is there a way to still keep the custom background on the top area but have the time, battery etc. in white even if the user is using light mode ?

question from:https://stackoverflow.com/questions/66062854/swiftui-how-to-keep-font-colours-in-top-edge-area

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can choose .preferredColorScheme

var body: some View {
  ZStack {...}
      .preferredColorScheme(.dark) // white tint on status bar
}

var body: some View {
  ZStack {...}
      .preferredColorScheme(.light) // black tint on status bar
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...