how do I put a blue square on an iPhone screen?

Asked on 08/02/2024

1 search

To put a blue square on an iPhone screen, you can use SwiftUI, which is a powerful framework for building user interfaces across all Apple platforms. Here’s a simple example of how you can create a blue square using SwiftUI:

import SwiftUI

struct ContentView: View {
    var body: some View {
        Rectangle()
            .fill(Color.blue)
            .frame(width: 100, height: 100)
    }
}

@main
struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

This code creates a Rectangle view, fills it with a blue color, and sets its width and height to 100 points. The ContentView is then used as the main view of the app.

For more detailed information on building user interfaces with SwiftUI, you can refer to the session What’s new in SwiftUI from WWDC 2024. This session covers various new features and improvements in SwiftUI, including how to create custom controls and layouts.