gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:38:45 27 4
gpt4 key购买 nike

下面是我在 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com