Swift 如何将我的按钮定位到屏幕底部?迅捷

Swift 如何将我的按钮定位到屏幕底部?迅捷,swift,swiftui,Swift,Swiftui,下面是我在SwiftUI中创建视图的代码。我想将欢迎按钮放置在屏幕底部,如下所示 struct welcomeViewControllerView: View { var body: some View { Text("Welcome") .font(.system(size: 20, design: .rounded)) .padding(.leading)

下面是我在SwiftUI中创建视图的代码。我想将欢迎按钮放置在屏幕底部,如下所示

struct welcomeViewControllerView: View {
      var body: some View {
            Text("Welcome")
              .font(.system(size: 20, design: .rounded))
              .padding(.leading)
              .multilineTextAlignment(.center)
              .background(

            Image("splashBackground")
              .resizable()
              .edgesIgnoringSafeArea(.all)
              .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
        
            Button(action:{print("button pressed")})
              {
                Text("Continue")
                .font(.system(size: 20, design: .rounded))
                .foregroundColor(.black)
                .frame(width: 300, height: 50, alignment: .center)
               .background((Image("buttonImage")).resizable().frame(width: 300, height: 50, alignment: .center))      
         }
      }
   }

class welcomeViewController: UIHostingController<welcomeViewControllerView> {
        required init?(coder: NSCoder)
         {
             super.init(coder: coder,rootView: welcomeViewControllerView());
          }
    
          override func viewDidLoad()
         {
           super.viewDidLoad()
            view.backgroundColor = .white
         }
}
如何将按钮定位到屏幕底部?我把屏幕贴在下面。我对使用SwiftUI相当陌生

结果:

结果:


你的问题包括一个背景图片,下面的代码使用ZStack和间隔符来获得下面有背景的布局。间隔者绝对是你水平或垂直推送内容的朋友

对于背景,因为它大部分是黑色的,所以我使用Color.black来绘制整个屏幕,并假设您可以使用较小的图像作为徽标。这使您可以发送一种不会扭曲的更小图像。分离屏幕颜色还可以匹配设备的亮/暗模式设置。如果感兴趣,请参阅ColorUIColor.systemBackground和@Environment.colorScheme

ZStack {
    Color.black
    
    Text("Welcome")
        .foregroundColor(.white)
        .font(.title)
    
    VStack {
        Image(systemName:"flame.fill")
            .resizable()
            .aspectRatio(contentMode:.fit)
            .foregroundColor(Color.blue)
            .frame(height:100)
            .padding([.top], 20)
        Spacer() // will spread content to top and bottom of VStack
        Button(action:{print("Continue")}){
            Text("Continue")
                .foregroundColor(.black)
                .padding(10)
                .background(Color.green)
                .cornerRadius(10)
        }
        Spacer()
            .frame(height:50)  // limit spacer size by applying a frame
    }
}
上面是你下面的内容:

您的问题包括背景图像,下面的代码使用ZStack和间隔符获得下面有背景的布局。间隔者绝对是你水平或垂直推送内容的朋友

对于背景,因为它大部分是黑色的,所以我使用Color.black来绘制整个屏幕,并假设您可以使用较小的图像作为徽标。这使您可以发送一种不会扭曲的更小图像。分离屏幕颜色还可以匹配设备的亮/暗模式设置。如果感兴趣,请参阅ColorUIColor.systemBackground和@Environment.colorScheme

ZStack {
    Color.black
    
    Text("Welcome")
        .foregroundColor(.white)
        .font(.title)
    
    VStack {
        Image(systemName:"flame.fill")
            .resizable()
            .aspectRatio(contentMode:.fit)
            .foregroundColor(Color.blue)
            .frame(height:100)
            .padding([.top], 20)
        Spacer() // will spread content to top and bottom of VStack
        Button(action:{print("Continue")}){
            Text("Continue")
                .foregroundColor(.black)
                .padding(10)
                .background(Color.green)
                .cornerRadius(10)
        }
        Spacer()
            .frame(height:50)  // limit spacer size by applying a frame
    }
}
上面是你下面的内容: