article

Thursday, August 12, 2021

SwiftUI Spacer sample aligned parent view

SwiftUI Spacer sample aligned parent view
Spacers can be used to push align views horizontally or vertically aligned at the top-left, middle and bottom-toght of their parent view
ContentView.swift
 
//
//  ContentView.swift
//  swiftuidev
//
//  Created by Cairocoders
//

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            HStack {
                Text("Text Left")
                Image(systemName: "arrow.left.circle.fill")
                Spacer()
            }.padding()
            
            Spacer()
            HStack {
                Image(systemName: "arrow.left.circle.fill")
                Spacer()
                Text("Text Center")
                Spacer()
                Image(systemName: "arrow.right.circle.fill")
            }.padding()
            
            Spacer()
            HStack {
                Spacer()
                Image(systemName: "arrow.right.circle.fill")
                Text("Text Right")
            }.padding()
            
        }
        .foregroundColor(Color.white)
        .background(RoundedRectangle(cornerRadius: 10))
        .foregroundColor(Color.gray)
        .font(.largeTitle)
        .padding()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Related Post