Padding
Part of the Introduction to SwiftUI section of Coddy's Swift journey. Lesson 14 of 50.
.padding() adds space around a view, between its content and whatever surrounds it. Without an argument it uses the standard amount of 16 points on every side:
Text("Tap to start")
.padding()Pass a number for a different amount, or name the edges that get it:
Text("A").padding(24)
Text("B").padding(.horizontal, 20)
Text("C").padding(.top).horizontal means the leading and trailing edges, .vertical the top and bottom. A single edge is .top, .bottom, .leading or .trailing.
Challenge
BeginnerGive the button text more room: add 24 points of padding on every side.
Try it yourself
import SwiftUI
@main
struct CoddyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Introduction to SwiftUI
Practice on your own: Swift playground