Make a VStack fill the width of the screen in SwiftUI

前端 未结 14 1707
失恋的感觉
失恋的感觉 2020-12-07 16:58

Given this code :

import SwiftUI

struct ContentView : View {
    var body: some View {
        VStack(alignment: .leading) {
            Text(\"Title\")
            


        
14条回答
  •  盖世英雄少女心
    2020-12-07 17:44

    A good solution and without "contraptions" is the forgotten ZStack

    ZStack(alignment: .top){
        Color.red
        VStack{
            Text("Hello World").font(.title)
            Text("Another").font(.body)
        }
    }
    

    Result:

提交回复
热议问题