1

I am trying to set the screen's background color to pink however, when I use edgesIgnoringSageArea(.all) it is being ignored and remains white.

Is this perhaps an Xcode 11 Beta 2 bug?

struct ContentView : View {
    @State var sliderValue: Float = 0

    var body: some View {
        VStack {
            Spacer()

            HStack {
                Image("lectric")
                Text("Some Text").font(.largeTitle)
            }

            Slider(value: $sliderValue, from: 1, through: 100, by: 1)

            Spacer()
        }.padding(.horizontal, 50)
         .background(Color.pink)
         .edgesIgnoringSafeArea(.all)
    }
}

enter image description here

Chris Burton
  • 1,085
  • 4
  • 16
  • 52
  • Hard to say. First, why aren't you already using beta 3? It's been available for 3 days and may answer your question. Second, have you tried using a `ZStack` to set background color? Maybe it's not the thing you want to do, but considering we're barely in beta 3... does it work? – dfd Jul 04 '19 at 22:31
  • Using Beta 3 and applying `ZStack` solves it. Thanks! – Chris Burton Jul 04 '19 at 22:59
  • Glad to help. maybe your code will work in a future beta - make sure to check it out each week. Isn't it fun working with bleeding edge software? :-) – dfd Jul 05 '19 at 01:36

4 Answers4

1

This code will change the navigation background color

 init(){
    UINavigationBar.appearance().backgroundColor = UIColor.blue
  }
Umer Waqas
  • 513
  • 4
  • 12
0

The automatic preview can't handle SafeArea yet.
If you run the application it will work as intended.

Ugo Arangino
  • 2,108
  • 1
  • 13
  • 16
-2

Thats the status bar. It is not handled by safe area. You have to change the window color or add an subview to change status bar color.

Here some ideas for status bar How to change Status Bar text color in iOS

and here are some ideas with custom views

How to change the status bar background color and text color on iOS 7?

Kurt57
  • 17
  • 1
  • 5
-2

So, it seems that you want to present same color in entire screen, the status bar component always stays separate from rest of the view so i would recommend try changing the status bar color specifically. Please try the below snippet method.

import UIKit

class ViewController: UIViewController {
override func viewDidLoad() {
    super.viewDidLoad()

   self.setStatusBarBackgroundColor(color: .blue)
    // Do any additional setup after loading the view, typically from a nib.
}


func setStatusBarBackgroundColor(color: UIColor) {

    guard let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else { return }

    statusBar.backgroundColor = color
}
}

You can obviously make this method generic also and call from appdelegate or some common class.

Subso
  • 1,193
  • 1
  • 8
  • 14