Vstack到屏幕中心
我必须显示以下内容,使用三个VSTACK显示它。但是,登录vstack是到屏幕底部。如何将其放置到屏幕的中心,然后将Google图像放在大多数屏幕上
struct Login: View {
var body: some View {
ZStack{
CustomNavigationBar() // To diplay image
VStack{
LoginView(lgnvwmmodel: lgnvwmmodel) //To display Login View
HelpView()
}
}
}
}
struct CustomNavigationBar: View{
var body: some View{
NavigationView{
Image(uiImage: UIImage(named: "google.png")!)
} .navigationViewStyle(StackNavigationViewStyle())
.navigationBarTitleDisplayMode(.inline)
.padding(0)
}
}
struct LoginView: View {
@State private var emailId: String = ""
@State private var password: String = ""
@State var ntwrkShowAlert = false
@State private var success = false
@State var isModal:Bool = false
@EnvironmentObject var DataGetting : DataStorage
@ObservedObject var monitor = NetworkMonitor()
@State private var isEmailValid : Bool = true
@State private var showingAlert = false
@State var chngpasscode = false
@State var btnClicked:CancelClicked = .none
@State var showPopup = false
@ObservedObject var lgnvwmmodel : LoginViewModel
var body: some View {
Text("Login")
.font(.custom("OpenSans-Bold", size: 24))
.padding(.top, 100)
TextField("Email ID", text: $emailId)
.onReceive(Just(emailId), perform: { _ in
if emailId.count >= 50{
emailId = String(emailId.prefix(50))
}
})
.modifier(customViewModifier(roundedCornes: 6, textColor: .black))
.frame(height: 100)
.padding([.leading, .trailing], 100)
SecureField("Password", text: $password)
.onReceive(Just(password), perform: { _ in
if password.count >= 50{
password = String(password.prefix(50))
}
})
.modifier(customViewModifier(roundedCornes: 6, textColor: .black))
.frame(height: 100)
.padding([.leading, .trailing], 100)
Button(action: {
}, label: {
Text("Forgot Password ?")
.underline()
.frame( height: 40, alignment: .trailing)
.padding(.leading, 320)
})
Button(action: {
if(DataGetting.strEmail == ""){
UserDefaults.standard.setValue(self.emailId, forKey:"Email")
}
if((DataGetting.strPassword) == 0){
UserDefaults.standard.setValue(self.password, forKey: "Password")
}
self.isModal = true
if(monitor.status == .connected){
self.ntwrkShowAlert = false
lgnvwmmodel.dataStorage = DataGetting
lgnvwmmodel.getUserIdDetails(emailId: emailId, password: password){ status in
do {
if(status){
success = true
}
}
}
}
else{
self.ntwrkShowAlert = true
}
}, label: {
Text("Sign In")
.frame(width: 200, height: 30)
.padding()
.background(Color.red)
.foregroundColor(Color.white)
.font(.custom("OpenSans-Bold", size: 28))
}).alert(isPresented: $ntwrkShowAlert){
return Alert(title: Text("Please check your internet connection"), message: Text(""), dismissButton: .default(Text("OK")))
}
}
}
struct HelpView: View{
@State private var isAlert = false
@State private var errorMessage: String = ""
var body: some View{
Button(action: {
}, label: {
Text("Help")
.frame(minWidth: 0, maxWidth: .infinity, maxHeight: 80)
.background(Color.red)
.foregroundColor(Color.white)
.font(.custom("OpenSans-Bold", size: 28))
}).alert(isPresented: $isAlert){
Alert(title: Text(self.errorMessage), message: Text(""), dismissButton: .default(Text("OK")))
}
}
}
I have to display like the following , used three VStacks to display it. However the login VStack is to the bottom of the screen. How to place it to the center of the screen and Google image to the top most of the screen
struct Login: View {
var body: some View {
ZStack{
CustomNavigationBar() // To diplay image
VStack{
LoginView(lgnvwmmodel: lgnvwmmodel) //To display Login View
HelpView()
}
}
}
}
struct CustomNavigationBar: View{
var body: some View{
NavigationView{
Image(uiImage: UIImage(named: "google.png")!)
} .navigationViewStyle(StackNavigationViewStyle())
.navigationBarTitleDisplayMode(.inline)
.padding(0)
}
}
struct LoginView: View {
@State private var emailId: String = ""
@State private var password: String = ""
@State var ntwrkShowAlert = false
@State private var success = false
@State var isModal:Bool = false
@EnvironmentObject var DataGetting : DataStorage
@ObservedObject var monitor = NetworkMonitor()
@State private var isEmailValid : Bool = true
@State private var showingAlert = false
@State var chngpasscode = false
@State var btnClicked:CancelClicked = .none
@State var showPopup = false
@ObservedObject var lgnvwmmodel : LoginViewModel
var body: some View {
Text("Login")
.font(.custom("OpenSans-Bold", size: 24))
.padding(.top, 100)
TextField("Email ID", text: $emailId)
.onReceive(Just(emailId), perform: { _ in
if emailId.count >= 50{
emailId = String(emailId.prefix(50))
}
})
.modifier(customViewModifier(roundedCornes: 6, textColor: .black))
.frame(height: 100)
.padding([.leading, .trailing], 100)
SecureField("Password", text: $password)
.onReceive(Just(password), perform: { _ in
if password.count >= 50{
password = String(password.prefix(50))
}
})
.modifier(customViewModifier(roundedCornes: 6, textColor: .black))
.frame(height: 100)
.padding([.leading, .trailing], 100)
Button(action: {
}, label: {
Text("Forgot Password ?")
.underline()
.frame( height: 40, alignment: .trailing)
.padding(.leading, 320)
})
Button(action: {
if(DataGetting.strEmail == ""){
UserDefaults.standard.setValue(self.emailId, forKey:"Email")
}
if((DataGetting.strPassword) == 0){
UserDefaults.standard.setValue(self.password, forKey: "Password")
}
self.isModal = true
if(monitor.status == .connected){
self.ntwrkShowAlert = false
lgnvwmmodel.dataStorage = DataGetting
lgnvwmmodel.getUserIdDetails(emailId: emailId, password: password){ status in
do {
if(status){
success = true
}
}
}
}
else{
self.ntwrkShowAlert = true
}
}, label: {
Text("Sign In")
.frame(width: 200, height: 30)
.padding()
.background(Color.red)
.foregroundColor(Color.white)
.font(.custom("OpenSans-Bold", size: 28))
}).alert(isPresented: $ntwrkShowAlert){
return Alert(title: Text("Please check your internet connection"), message: Text(""), dismissButton: .default(Text("OK")))
}
}
}
struct HelpView: View{
@State private var isAlert = false
@State private var errorMessage: String = ""
var body: some View{
Button(action: {
}, label: {
Text("Help")
.frame(minWidth: 0, maxWidth: .infinity, maxHeight: 80)
.background(Color.red)
.foregroundColor(Color.white)
.font(.custom("OpenSans-Bold", size: 28))
}).alert(isPresented: $isAlert){
Alert(title: Text(self.errorMessage), message: Text(""), dismissButton: .default(Text("OK")))
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是固定的简化版本(没有模型或按钮操作)。我不确定为什么您将Google徽标包裹在NavigationView中? - 因此,我跳过了它,因为它会引起布局问题。
Here is a fixed simplified version (without models or button actions). I'm not sure why you wrapped the Google logo in a NavigationView? – so I skipped it as it causes layout issues.