Make sure you put the resizable() modifier on your image (and an .aspectRatio() set to fit). If you have this placed in a VStack or HStack with a fixed size, the size of the image will automatically resize if less space is available because of more lines of text.
You can then also give your text a lineLimit() modifier set to 2 to make sure that no more than 2 lines will be displayed.
VStack {
Image("Album")
.resizable()
.aspectRatio(contentMode: .fit)
Text("Some long text here that will span two lines")
.lineLimit(2)
}.frame(width: 200, height: 200)
Post
Replies
Boosts
Views
Activity
Looks like this is not added yet (the new Map view in SwiftUI is quite basic at the moment).
If you need it, you can embed an MKMapView from UIKit using UIViewRepresentable that will give you all the flexibility you need. There is a good tutorial on hackingwithswift.com
Ah yes, I now tried it in a project, and that works as expected. Before I tried it in a Playground, which did not work. So issue solved :)
Yes I would put the code in a separate function. You can call this function during .onAppear on one of your views. You could then also keep it as an action for your button, so clicking the button would also execute the code block.
Where and how are you getting your images? Are you loading the images in the OnAppear of your gridcells?
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)
}
}
See the reply here..
https://developer.apple.com/forums/thread/671690
Put a .navigationTitle() modifier with the title of the file on the VStack inside of the NavigationView in your ts view.
NavigationView {
VStack {
// Your text views
}.navigationTitle(name)
}
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)