SwiftUI is a declarative framework for building user interfaces in Swift. Here is an overview of some of its basic syntax and features.
Text("Hello, world!")
.font(.title)
.foregroundColor(.blue)
Image("imageName")
.resizable()
.aspectRatio(contentMode: .fit)
Button(action: {
// Button action
}) {
Text("Button")
}
List {
Text("Item 1")
Text("Item 2")
}
VStack {
Text("Top")
Text("Middle")
Text("Bottom")
}
HStack {
Text("Left")
Text("Center")
Text("Right")
}
ZStack {
Image("backgroundImage")
.resizable()
.aspectRatio(contentMode: .fill)
Text("Foreground")
}
NavigationView {
List {
NavigationLink(destination: DetailView()) {
Text("Item 1")
}
NavigationLink(destination: DetailView()) {
Text("Item 2")
}
}
}
struct ContentView: View {
@State var showModal = false
var body: some View {
Button(action: {
showModal = true
}) {
Text("Show Modal")
}
.sheet(isPresented: $showModal) {
ModalView()
}
}
}