article

Saturday, May 8, 2021

SwiftUI How to make view fill width or height of screen

SwiftUI How to make view fill width or height of screen
 
//
//  ContentView.swift
//  Testapp
//
//  Created by Cairocoders
//

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Full size text view!")
            .foregroundColor(Color.white)
            .frame(maxWidth: .infinity, maxHeight: .infinity)
            .background(Color.blue)
    }
}

struct SecondView: View {
    var body: some View {
        VStack {
            Text("VStack Text View")
                .foregroundColor(Color.white)
                .background(Color.blue)
        }.frame(maxWidth: .infinity, maxHeight: .infinity)
            .border(Color.red, width: 2) // Set VStack border to make it visible
        
    }
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            ContentView()
            SecondView()
        }
    }
}

Related Post