下面是我在 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
}
}
Run Code Online (Sandbox Code Playgroud)
如何将按钮放置在屏幕底部?我发布了下面的屏幕。我对使用 SwiftUI 还很陌生。