如何在 MacOS (11.4) 上将 LazyVGrid 放在 Image swiftUI 旁边
How to put LazyVGrid next to Image swiftUI on MacOS (11.4)
(MacOS 应用程序)
我正在尝试在图像旁边放置一个 lazyvgrid。使图像具有特定大小并让 LazyVGrid 占用其余的宽度。我设置了图像的框架,但网格没有占用额外的 space 并且图像和网格的左侧和右侧有额外的空白 space。
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)
}
}
}
尝试这样的事情:
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)
}
}
(MacOS 应用程序) 我正在尝试在图像旁边放置一个 lazyvgrid。使图像具有特定大小并让 LazyVGrid 占用其余的宽度。我设置了图像的框架,但网格没有占用额外的 space 并且图像和网格的左侧和右侧有额外的空白 space。
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)
}
}
}
尝试这样的事情:
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)
}
}