I have this simple SwiftUI code. I want all symbols to be aligned centered, just like the cloud symbol.
struct ContentView : View {
var body: some View {
HStack(alignment: .center, spacing: 10.0) {
Image(systemName: "cloud.sun")
Image(systemName: "cloud")
Image(systemName: "cloud.bolt")
Text("Text")
}.font(.title)
}
}
But as you can see below, the first and the last symbol are not centered. Am I missing something, or is this a bug?
Cheers!
This is what it's going on.
The
Image
views are not resizing.It looks like they're not aware of their intrinsic content size, or maybe it reports the wrong value.
To fix it:
...make the
Images
resizable, and also make sure the aspect ratio is set to.fit
, or they will stretch.Set also frame on the
HStack
or it will expand to fill the whole screen.@MartinR suggested an even better solution - creating the images via
UIImage
- see his comment below.Output: