0

(MacOS 应用程序)我正在尝试在图像旁边放置一个lazyvgrid。使图像具有特定大小,并让 LazyVGrid 占据其余的宽度。我设置了图像的框架,但网格没有占用额外的空间,并且图像和网格的左右两侧都有额外的空白空间。

import SwiftUI

struct ContentView: View {
    var body: some View {
        HStack{
            LazyVGrid(columns: [GridItem(
                 .adaptive(minimum: 40)
            )]){
                Text("Placeholder")
                Text("Placeholder")
            }
            .padding()
            .background(Color.blue)
            Image("bla")
                .resizable()
                //.scaledToFit()
                .frame(width: 100, height: 100)
                .background(Color.pink)
        }
    }
}

左侧和右侧的额外空间

4

1 回答 1

1

尝试这样的事情:

struct ContentView: View {
    var body: some View {
        HStack {
            LazyVGrid(columns: [GridItem(.adaptive(minimum: 40))]){
                Text("Placeholder")
                Text("Placeholder")
            }
            .padding()
            // put this here if you want the width and the height to expand
          //  .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
            .background(Color.blue)
            // put this here if you want just the width to expand
            .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)

            Image(systemName: "globe")
                .resizable()
                //.scaledToFit()
                .frame(width: 100, height: 100)
                .background(Color.pink)

        }.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
    }
}
于 2021-06-28T04:04:04.923 回答