How to Set Up a Basic Swift Project & Align Items Horizontally and Vertically
Welcome to this Swift tutorial! In this video, I’ll walk you through setting up a basic Swift project (using UIKit or SwiftUI) and show you how to align UI elements both horizontally and vertically for a polished layout. 📌 What You’ll Learn: - Setting up a new Swift project in Xcode - Adding UI elements - Aligning views horizontally (side by side) - Aligning views vertically (stacked top to bottom) - Best practices for clean and responsive layouts ⏱️ Timestamps: 00:00 - Intro 00:30 - Creating a new Swift project 02:50 - Editing/Adding UI elements 05:00 - Adding another Horizontal alignment (HStack with image at left and text on right) 08:00 - Adding another Horizontal alignment (HStack with images side by side) 11:00 - Fixing spacing between horizontal & vertical layouts Code: import SwiftUI struct ContentView: View { var body: some View { VStack(spacing: 0) { VStack{ Image(systemName: "heart.fill") .imageScale(.large) .foregroundColor(.pink) .font(.system(size:60)) Text("Developer Resources!") .font(.title) } .padding() HStack { Image(systemName: "heart.fill") .imageScale(.large) .foregroundColor(.pink) .font(.system(size:60)) Text("Developer Resources!") .font(.title) } .padding(80) // ← External padding .background(Color.gray.opacity(0.2)) HStack (spacing: 40) { Image(systemName: "diamond.fill") .imageScale(.large) .foregroundColor(.blue) .font(.system(size:60)) Image(systemName: "diamond.fill") .imageScale(.large) .foregroundColor(.yellow) .font(.system(size:60)) } .padding(80) // ← External padding .background(Color.mint.opacity(0.2)) } } } #Preview { ContentView() }
Download
0 formatsNo download links available.