swift - 如何将我的按钮定位到屏幕底部?用户界面

标签 swift swiftui

下面是我在 SwiftUI 中创建 View 的代码。我要定位我的 欢迎按钮 到屏幕底部,如下所示。

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 还很陌生。
enter image description here

最佳答案

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "heart.fill")
                .resizable()
                .frame(width: 60, height: 60)
                .foregroundColor(.red)
            
            Group{
                Text("Welcome!")
                    .font(.title)
                
                Button(action: {
                    print("tapped!")
                }, label: {
                    Text("Continue")
                        .foregroundColor(.white)
                        .frame(width: 200, height: 40)
                        .background(Color.green)
                        .cornerRadius(15)
                        .padding()
                })
            }.frame(maxHeight: .infinity, alignment: .bottom)
        }
    }
}
结果:
enter image description here

关于swift - 如何将我的按钮定位到屏幕底部?用户界面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65135725/

相关文章:

ios - Swift 1.2 lowercaseString 与 enumerateSubstringInRange 崩溃

swift - 内部渐变颜色 UIBezierPath

ios - 对于 UIButton,我同时使用了标题和图像。我希望标题先于图像

swiftui - View 不会在嵌套 ForEach 循环中重新呈现

swift - 在 SwiftUI 中设置切换颜色

ios - 如何使用模数和指数生成公钥?

ios - 更改 MoreNavigationController TableView Row 中的角标(Badge)值文本和背景颜色?

ios - SwiftUI:@State 已修改但在阅读之后的行时看似未更改

ios - 如何在 SwiftUI 中实现协议(protocol)和委托(delegate)

ios - 如何在 SwiftUI 中动画/过渡文本值更改