Lec05 Creating and Combining Views — SwiftUI Tutorials _ Apple Developer Documentation
Lec05 Creating and Combining Views — SwiftUI Tutorials _ Apple Developer Documentation
SwiftUI Tutorials
SwiftUI Essentials
40min
Estimated Time Project files Xcode 12
Section 1
Step 1
Step 2
Step 3
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views 2/18
2/1/2021 Creating and Combining Views — SwiftUI Tutorials | Apple Developer Documentation
Step 4
Step 5
Step 6
Tip
Step 7
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views 3/18
2/1/2021 Creating and Combining Views — SwiftUI Tutorials | Apple Developer Documentation
Section 2
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views 4/18
2/1/2021 Creating and Combining Views — SwiftUI Tutorials | Apple Developer Documentation
Step 1
Step 2
Step 3
Step 4
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views 5/18
2/1/2021 Creating and Combining Views — SwiftUI Tutorials | Apple Developer Documentation
Your code is always the source of truth for the
view. When you use the inspector to change or
remove a modifier, Xcode updates your code
immediately to match.
Step 5
Step 6
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views 6/18
2/1/2021 Creating and Combining Views — SwiftUI Tutorials | Apple Developer Documentation
Section 3
Step 1
Step 2
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views 7/18
2/1/2021 Creating and Combining Views — SwiftUI Tutorials | Apple Developer Documentation
Step 3
Step 4
Step 5
Step 6
Step 7
Step 8
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views 8/18
2/1/2021 Creating and Combining Views — SwiftUI Tutorials | Apple Developer Documentation
adding a Spacer to the horizontal stack
holding the two text views.
Step 9
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views 9/18
2/1/2021 Creating and Combining Views — SwiftUI Tutorials | Apple Developer Documentation
Section 4
Step 1
Step 2
Step 3
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views 10/18
2/1/2021 Creating and Combining Views — SwiftUI Tutorials | Apple Developer Documentation
Step 4
Step 5
Step 6
Step 7
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views 11/18
2/1/2021 Creating and Combining Views — SwiftUI Tutorials | Apple Developer Documentation
Section 5
Step 1
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views 12/18
2/1/2021 Creating and Combining Views — SwiftUI Tutorials | Apple Developer Documentation
Step 2
Step 3
Step 4
Step 5
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views 13/18
2/1/2021 Creating and Combining Views — SwiftUI Tutorials | Apple Developer Documentation
Section 6
ContentView.swiftPreview
↗
1 import SwiftUI
2
3 struct ContentView: View {
4 var body: some View {
5 VStack(alignment: .leading) {
Step 1 6 Text("Turtle Rock")
7 .font(.title)
In the Project navigator, select the Content
View.swift file. 8
9 HStack {
10 Text("Joshua Tree National Park")
11 .font(.subheadline)
12 Spacer()
13 Text("California")
14 .font(.subheadline)
Step 2 15 }
16 }
Embed the VStack that holds the three text
17 .padding()
views in another VStack.
18 }
19 }
20
21 struct ContentView_Previews: PreviewProvider {
22 static var previews: some View {
23 ContentView()
Step 3 24 }
25 }
Add your custom MapView to the top of the
stack. Set the size of the MapView with
frame(width:height:).
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views 15/18
2/1/2021 Creating and Combining Views — SwiftUI Tutorials | Apple Developer Documentation
Step 4
Step 5
Step 6
Step 7
Step 8
Step 9
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views 16/18
2/1/2021 Creating and Combining Views — SwiftUI Tutorials | Apple Developer Documentation
Step 10
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views 17/18
2/1/2021 Creating and Combining Views — SwiftUI Tutorials | Apple Developer Documentation
Question 1 of 4
When creating a custom SwiftUI view, where do you declare the viewʼs layout?
Next
Get started
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views 18/18