Date: 19/06/2025
Author: Bruno
Today, I dove deeper into SwiftUI and explored the powerful ways to structure layouts using stacks—specifically ZStack
, HStack
, and VStack
. I also worked with images, learning how to resize and position them effectively. Here’s a breakdown of what I learned:
HStack
(Horizontal Stack) – Arranges views side by side in a horizontal line.VStack
(Vertical Stack) – Stacks views vertically, one above the other.ZStack
(Z-axis Stack) – Layers views on top of each other, useful for overlapping elements.We can see an example of this in this picture:
I also explored how to adjust images in SwiftUI using modifiers:
.resizable()
– Allows an image to scale to fit its container..scaledToFit()
– Maintains aspect ratio while fitting within bounds..ignoresSafeArea()
– Extends the view beyond the safe area (great for full-screen backgrounds).Spacer()
– Pushes views apart, helping with flexible layouts.An example would be:
Image(systemName: "star.fill")
.resizable()
.scaledToFit()
.frame(width: 100, height: 100)
I downloaded SF Symbols, Apple’s built-in icon library, which integrates seamlessly with SwiftUI. Using Image(systemName:)
, we can easily add scalable, customizable icons to our apps.
Check the code of the app here, ciao!