Simple Login Screen using SwiftUI
===========================
//
// LoginScreen.swift
// iOSApp1
//
// Created by Pratap Kumar on 04/05/23.
//
import SwiftUI
struct LoginScreen: View {
@State var username : String = "";
@State var email : String = "";
@State var password :String = "";
var colorBlue: Color = Color.blue
var grayBackground: Color = Color.gray.opacity(0.1)
@State private var showingAlert = false
var body: some View {
VStack{
// Welcome Label
Text("Welcome, User")
.foregroundColor(colorBlue)
.padding(.bottom, 30).font(.largeTitle)
// Email Address Field
HStack{
Image(systemName:"envelope.fill").foregroundColor(Color.blue)
TextField("Email Address", text: $email)
}.padding().background(grayBackground).cornerRadius(5.0).padding(.bottom,10)
// Password Field
HStack{
Image(systemName:"lock.fill").foregroundColor(Color.blue)
SecureField("Password", text: $password)
}.padding().background(grayBackground).cornerRadius(5.0).padding(.bottom,10)
Button(action: {
showingAlert = true
}){
Text("Login")
.font(.headline)
.foregroundColor(.white)
.padding()
.frame(width: 150, height: 50)
.background(colorBlue)
.cornerRadius(10.0)
} .alert(isPresented: $showingAlert) {
Alert(title: Text("Login Details"),
message: Text("Email : \(email)\nPassword : \(password)"),
primaryButton: .destructive(Text("OK")),
secondaryButton: .cancel(Text("Cancel")))
}
}.padding(.horizontal)
}
}
struct LoginScreen_Previews: PreviewProvider {
static var previews: some View {
LoginScreen()
}
}
Screenshot
============
No comments:
Post a Comment