SwiftUI Image – Padding
To set padding for Image, add padding()
modifier to the Image. You may specify the sides on which the padding has to be set, and the length of padding to be set.
Example
In this example, we shall display an image from assets in two Image views with padding on all sides. The first Image shall have a default padding length, and the second Image shall have a padding length of 50.0
.
ContentView.swift
import SwiftUI
struct ContentView: View {
var body: some View {
Image("sunrise")
.resizable()
.aspectRatio(contentMode: .fit)
.padding(.all)
Image("sunrise")
.resizable()
.aspectRatio(contentMode: .fit)
.padding(.all, 50)
}
}
Screenshot

Summary
Summarising thisĀ SwiftUI Tutorial, we learned how to set padding for an Image using SwiftUI.