import SwiftUI
struct ProfileInfoView: View {
var body: some View {
VStack(spacing: 0) {
Image(systemName: "person.circle.fill")
.resizable()
.frame(width: 100, height: 100)
.padding(.top, 20)
Text("John Appleseed")
.font(.title)
.padding(.top, 20)
Text("iOS developer and coffee lover.")
.font(.body)
.multilineTextAlignment(.center)
.padding(.top, 10)
}
.frame(maxWidth: .infinity)
.padding(20)
.background(Color(UIColor.systemBackground))
}
}
struct ProfileInfoView_Previews: PreviewProvider {
static var previews: some View {
ProfileInfoView()
}
}We used a VStack to stack the profile picture, name, and bio vertically. The spacing parameter sets the default space between elements to 0 points.
We added padding(.top, 20) to the profile picture and name to create 20 points vertical spacing above them, and 10 points above the bio text.
All elements are centered horizontally by default in a VStack, but we ensured the VStack takes full width with .frame(maxWidth: .infinity) so the content is centered in the screen.
Finally, we added .padding(20) around the VStack to keep content away from screen edges, making the layout neat and balanced.