Saturday, February 6, 2021

Xcode 11.6 (Swift 5.2.4) - Hello World and how to set the background color programmatically

 code:

import SwiftUI


struct ContentView: View {

    let screenWidth = UIScreen.main.bounds.width

    var body: some View {

        ZStack {

            Color.yellow

            .edgesIgnoringSafeArea(.all)

            Text("Hello, World!")

            

            Text("Study Swift")

            .position(CGPoint(x: screenWidth/2, y: 400))

            

        }

    }

}


struct ContentView_Previews: PreviewProvider {

    static var previews: some View {

        ContentView()

    }

}

Result:


Reference:


How to set a background color for the viewController in swiftUI? (StackOverflow)

No comments:

Post a Comment