Post

Replies

Boosts

Views

Activity

Reply to SwiftUI MapKit Callouts
You can create your own custom AnnotationViews using the MapAnnotation. See below an example that creates a callout with an image. Map(coordinateRegion: $coordinateRegion, annotationItems: annotations) { annotation in    MapAnnotation(coordinate: annotation.coordinate, anchorPoint: CGPoint(x: 0.5, y: 1)) {        AssetAnnotationView(image: annotation.image)    } } Where AssetAnnotationView could look like this: struct AssetAnnotationView: View {     var image: UIImage     var body: some View {         Image(uiImage: image)             .resizable()             .aspectRatio(contentMode: .fill)             .frame(width: 100, height: 100)             .cornerRadius(3.0)             .padding(4)             .callOut()         }     } } callout is a custom modifier here that draws the callout shape (a rounded rect with a beak/point to the bottom of the view)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’21
Reply to ScrollView shrink to fit
Not really sure what your scenario is, so there might be a simpler way. However, I had a somewhat similar situation, but this was without a ScrollView. I found something on Hacking With Swift forum that got me to a solution (bit of a hack) Create a State variable that stores the CGSize of your content Put an overlay on your content view that has a GeometryReader with a Color.Clear view (this is the tacky part) In the onAppear of your Color.Clear, set the CGSize State to your GeometryProxy's size Use a basic .frame modifier to set the size of your Scrollview to the size of the State CGSize struct ContentView: View {     @State private var contentSize: CGSize = .zero     var body: some View {         ScrollView {             Rectangle()                 .fill(Color.blue)                 .frame(width: 100, height: 100)                 .overlay(                     GeometryReader { geo in                         Color.clear.onAppear {                             contentSize = geo.size                         }                     }                 )         }         .background(Color.red)         .frame(maxWidth: contentSize.width, maxHeight: contentSize.height)     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21