微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 MacOS (11.4) 上将 LazyVGrid 放在 Image swiftUI 旁边

如何解决如何在 MacOS (11.4) 上将 LazyVGrid 放在 Image swiftUI 旁边

(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)
        }
    }
}

extra space to the left and to the right

解决方法

尝试这样的事情:

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,alignment: .leading)

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

        }.frame(maxWidth: .infinity,alignment: .leading)
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。