Directions UI Layout
Maps UIKit SwiftUI
Moving on with another application in the SwiftUI portion of the course is the Directions Searching application. The idea behind this program is to illustrate some core concepts of SwiftUI:
  • NavigationLink
  • Environment Object
  • View Componentization
  • Combine publishers
In this specific lesson, we'll be laying out everything in the User Interface with stacks and an MKMapView.

Comments (1)
3 years ago
Brian, I used GeometryReader instead of the UIApplication to get the struct DirectionsSearchView: View { var body: some View { GeometryReader { geometry in ZStack(alignment: .top) { VStack(spacing: 0) { VStack { Spacer() .frame(height: HStack(spacing: 16) { Image(uiImage: #imageLiteral(resourceName: "start_location_circles")) HStack { Text("Source") Spacer() } .padding() .background(Color.white) .cornerRadius(3) } HStack(spacing: 16) { Image(uiImage: #imageLiteral(resourceName: "annotation_icon").withRenderingMode(.alwaysTemplate)) .foregroundColor(.white) HStack { Text("Destination") Spacer() } .padding() .background(Color.white) .cornerRadius(3) } } .padding() .background( DirectionsMapView() .edgesIgnoringSafeArea(.bottom) }.edgesIgnoringSafeArea(.top) } } } }