如何在图像前面制作一个按钮,但在 SwiftUI 中限制在视图的左下角和右下角?
How to make a button in front of an image but constrained to the left bottom and right of the view in SwiftUI?
如何扩展登录视图,使其左侧被限制在左侧,右侧也被限制在右侧?
import SwiftUI
struct Intro: View {
var body: some View {
ZStack {
Image("IntroImage")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(alignment: .center)
VStack {
Spacer()
Button(action: {}, label: {
Text("Sign in")
.foregroundColor(Color.black)
.padding()
.background(Color.green)
})
}
}
.ignoresSafeArea()
}
}
struct Intro_Previews: PreviewProvider {
static var previews: some View {
Intro()
}
}
我希望它看起来像这样:
我使用 640 × 1136 png 作为图片。我正在所有设备上测试它,包括 iPhone 11.
将 frame(maxWidth: .infinity)
添加到您的 Button
的 Text
:
Button(action: {}, label: {
Text("Sign in")
.frame(maxWidth: .infinity)
.foregroundColor(Color.black)
.padding()
.background(Color.green)
})
在 iPhone 11 上的出现:
如何扩展登录视图,使其左侧被限制在左侧,右侧也被限制在右侧?
import SwiftUI
struct Intro: View {
var body: some View {
ZStack {
Image("IntroImage")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(alignment: .center)
VStack {
Spacer()
Button(action: {}, label: {
Text("Sign in")
.foregroundColor(Color.black)
.padding()
.background(Color.green)
})
}
}
.ignoresSafeArea()
}
}
struct Intro_Previews: PreviewProvider {
static var previews: some View {
Intro()
}
}
我希望它看起来像这样:
我使用 640 × 1136 png 作为图片。我正在所有设备上测试它,包括 iPhone 11.
将 frame(maxWidth: .infinity)
添加到您的 Button
的 Text
:
Button(action: {}, label: {
Text("Sign in")
.frame(maxWidth: .infinity)
.foregroundColor(Color.black)
.padding()
.background(Color.green)
})
在 iPhone 11 上的出现: