带图像的SwiftUI 2按钮

带图像的SwiftUI 2按钮,swiftui,Swiftui,我想在视图中添加带有图像的按钮,就像Swiftui2中带有图像的twitter按钮一样,但它并没有填充到任何方向 这个问题有什么解决办法。我希望你做得很好 这段代码应该可以做到这一点 VStack { Spacer() Button(action: {}) { Image(systemName: "cloud.fill") .padding() .background(Color.blue)

我想在视图中添加带有图像的按钮,就像Swiftui2中带有图像的twitter按钮一样,但它并没有填充到任何方向


这个问题有什么解决办法。

我希望你做得很好

这段代码应该可以做到这一点

VStack {
    Spacer()
    Button(action: {}) {
        Image(systemName: "cloud.fill")
            .padding()
            .background(Color.blue)
            .foregroundColor(Color.white)
            .clipShape(Circle())
            .shadow(radius: 8)
    }
}
.frame(maxWidth: .infinity, alignment: .trailing)
.padding()
通过将按钮放在VStack中,并在其前面放置一个垫片,您将把按钮推到屏幕底部。然后,通过在其上放置一个框架,使宽度为.infinity,并使其对齐尾随,您将进一步将按钮推到屏幕的尾随侧,在这种情况下,将按钮推到右下角

编辑:包含完整代码
是否有您想要的图像/示例?不清楚您想要的填充和哪个按钮。问题已更新。您可以进一步修改大小和填充以达到所需的结果。非常感谢您的回答,但这是使用导航菜单移动。嘿!我得到它在我这边的工作,我会编辑我的文章,包括完整的代码现在抱歉,我现在明白了。
VStack {
    Spacer()
    Button(action: {}) {
        Image(systemName: "cloud.fill")
            .padding()
            .background(Color.blue)
            .foregroundColor(Color.white)
            .clipShape(Circle())
            .shadow(radius: 8)
    }
}
.frame(maxWidth: .infinity, alignment: .trailing)
.padding()
struct WeatherView: View {
    var body: some View {
        VStack(alignment: .leading, spacing: 0) {
            HStack(spacing: 5) {
                Text("Rainy")
                    .foregroundColor(.black)
                    .font(.largeTitle)
                    .fontWeight(.medium)
                
                Spacer()
                
                Button(action: {}) {
                    Image("menu").resizable().frame(width: 24, height: 24)
                }
                
            }
            .foregroundColor(Color("black"))
            .padding()
            
            VStack {
                Spacer()
                Button(action: {}) {
                    Image("cloud")
                        .padding()
                        .background(Color.blue)
                        .foregroundColor(Color.white)
                        .clipShape(Circle())
                        .shadow(radius: 8)
                }
            }
            .frame(maxWidth: .infinity, alignment: .trailing)
            .padding()
        }
    }
}