Table of Contents
Image views
// Shows an Image with an image named “Name”
// Image should be imported into Assets.xcassets
// prior to referencing the image by name
Image("Name")
.resizable() // Allows the image to be resized
.aspectRatio(contentMode: .fit) // Maintan aspect ratioText label
Text(“Large Title”)
.font(.largeTitle) // Change preset font size
.fontWeight(.bold) // Change the font weight
.foregroundColor(.blue) // Change the text colorLists
// Showing a list of Identifiable object
List(restaurants) { restaurant in
Text(restaurant.name)
}
// Showing a list of non-identifiable objects
let words = ["Hello", "World"]
List(words, id: \.self) { word in
Text(word)
}ForEach
// Iterating over an Identifiable sequence
ForEach(restaurants) { restaurant in
Text(restaurant.name)
}
// Iterating over a non-identifiable sequence
ForEach(words, id: \.self) {word on
Text(word)
}Stack views
Vertical Stack (VStack)
VStack {
Text("Hello") // Shows on top
Text("World") // Shows at the bottom of Hello
}Horizontal Stack (HStack)
HStack {
Text("Hello") // Shows at the left
Text("World") // Shwos right of Hello
}Z Stack (ZStack)
ZStack {
Image("1") // Image at the backslash
Text("Hello") // Text in front
}Scroll Views
Vertical Scrolling View
ScrollView {
VStack {
ForEach(restaurants) { restaurant in
Text(restaurant.name)
}
}
}Horizontal Scrolling View
ScrollView {
HStack {
ForEach(recipe) { recipe in
Image(recipe.photo)
}
}
}Navigation Stack
NavigationStack {
List(restaurants) {restaurant in
NavigationLink(restaurant.name, value: restaurant)
}
.navigationDestination(for: Restaurant.self) { restaurant in
RestaurantDetails(restaurant)
}
}