Skip to content

Instantly share code, notes, and snippets.

@culjo
Last active July 15, 2020 00:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save culjo/203775e4032c7bbc6b6a5587533de2ed to your computer and use it in GitHub Desktop.
Save culjo/203775e4032c7bbc6b6a5587533de2ed to your computer and use it in GitHub Desktop.
A SwiftUI login screen
import SwiftUI
struct ContentView : View {
@EnvironmentObject var loginViewModel: LoginViewModel
@State var counter: Int = 0
var body: some View {
VStack() {
VStack {
Image("logo").resizable().aspectRatio(contentMode: ContentMode.fit)
.frame(width: 74.0, height: 74.0).padding(Edge.Set.bottom, 20)
Text("Login").bold().font(.title)
Text("Explore the world of Swift UI").font(.subheadline)
.padding(EdgeInsets(top: 0, leading: 0, bottom: 70, trailing: 0))
TextField($loginViewModel.email, placeholder: Text("Email"))
.padding()
.background(Color("flash-white"))
.cornerRadius(4.0)
.padding(EdgeInsets(top: 0, leading: 0, bottom: 15, trailing: 0))
SecureField($loginViewModel.password, placeholder: Text("Password")) {
// submit the password
}.padding().background(Color("flash-white"))
.cornerRadius(4.0)
.padding(.bottom, 10)
HStack() {
Spacer()
NavigationButton(destination: DashboardView()) {
Text("Forgot Password?").font(.system(size: 15))
}
}.padding(.bottom, 40)
Button(action: submit) {
HStack(alignment: .center) {
Spacer()
Text("Login").color(Color.white).bold()
Spacer()
}
}.padding().background(Color.green).cornerRadius(4.0)
}.padding()
}.padding()
}
func submit() {
loginViewModel.performLogin()
}
}
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView().environmentObject(LoginViewModel())
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment