Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.

Follow publication

Member-only story

12 Powerful SwiftUI Component

Jerry PM
Stackademic
Published in
10 min readMar 24, 2025

You should start using this component to improve your code

1. LazyVGrid and LazyHGrid

This might still be rarely used, but many people haven’t utilized it yet when developing apps with SwiftUI.

However, you’re probably already familiar with the use of ‘Lazy,’ such as ‘LazyVStack’ or ‘LazyHStack.’ The usage is quite similar.

2These allow you to create complex grid layouts with lazy loading, which is great for performance when displaying large datasets.

struct LazyGridExample: View {
let columns = [
GridItem(.flexible()),
GridItem(.flexible()),
GridItem(.flexible())
]

var body: some View {
ScrollView {
LazyVGrid(columns: columns, spacing: 20) {
ForEach(0..<50) { index in
Text("Item \(index)")
.frame(height: 50)
.frame(maxWidth: .infinity)
.background(Color.blue.opacity(0.2))
.cornerRadius(8)
}
}
.padding()
}
}
}

Here the preview UI

Source by Author

2. ViewThatFits

Automatically selects the first child view that fits within available space, perfect for responsive designs.

ViewThatFits will choose the most appropriate view based on available space

import SwiftUI

struct ViewThatFitsExample: View {
var body: some View {
VStack {
Text("ViewThatFits Example")
.font(.title)
.padding()

ViewThatFits(in: .horizontal) {
// First option (highest priority) - full view
HStack {
Image(systemName: "star.fill")
.foregroundColor(.yellow)
Text("This is the complete text that will be displayed if there's enough space")
Image(systemName: "star.fill")
.foregroundColor(.yellow)
}
.padding()

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.

No responses yet

Write a response