SwiftUI Login Screen Designs
Discover our SwiftUI Login Screen components designed to offer a range of options, from traditional email logins to social media and biometric authentication. Enhance your app's security and user experience with our customizable sign-in forms. Upgrade to premium to access all advanced features and exclusive components.
Simple Login Page
import SwiftUI
struct LoginView: View {
@State private var email: String = ""
@State private var password: String = ""
@State private var isLoading: Bool = false
@State private var errorMessage: String?
var body: some View {
VStack(spacing: 20) {
Spacer()
// Lock icon
Image(systemName: "lock.fill")
.resizable()
.scaledToFit()
.frame(width: 50, height: 50)
.foregroundColor(.blue)
.padding(.bottom, 20)
// Welcome text
Text("Welcome to ")
.font(.title)
.fontWeight(.bold) +
Text("SwiftUI.art")
.font(.title)
.fontWeight(.bold)
.foregroundColor(.blue)
// Subtitle text
Text("Log in to your account")
.font(.subheadline)
.foregroundColor(.gray)
// Email TextField
TextField("Email address", text: $email)
.padding()
.background(Color(.secondarySystemBackground))
.cornerRadius(8)
.autocapitalization(.none)
.keyboardType(.emailAddress)
.textContentType(.emailAddress)
// Password SecureField
SecureField("Password", text: $password)
.padding()
.background(Color(.secondarySystemBackground))
.cornerRadius(8)
.textContentType(.password)
// Error message
if let errorMessage = errorMessage {
Text(errorMessage)
.foregroundColor(.red)
.font(.footnote)
.padding([.top, .horizontal])
}
// Sign In button
Button(action: {
signIn()
}) {
if isLoading {
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: .white))
.frame(maxWidth: .infinity)
.padding()
} else {
Text("Sign in")
.foregroundColor(.white)
.frame(maxWidth: .infinity)
.padding()
}
}
.background(Color.black)
.cornerRadius(8)
.disabled(isLoading)
// Face ID button
Button(action: {
// Action for Face ID
}) {
HStack {
Image(systemName: "faceid")
.foregroundColor(.black)
Text("Face ID")
.foregroundColor(.black)
}
.frame(maxWidth: .infinity)
.padding()
.background(Color(.secondarySystemBackground))
.cornerRadius(8)
}
Spacer()
// Disclaimer text
Text("By clicking \"Sign in\" above, you agree to SwiftUI.art's Terms & Conditions and Privacy Policy.")
.font(.footnote)
.foregroundColor(.gray)
.multilineTextAlignment(.center)
.padding(.horizontal, 20)
Spacer()
}
.padding()
}
func signIn() {
// Reset the error message
errorMessage = nil
// Validate email and password
guard !email.isEmpty, !password.isEmpty else {
errorMessage = "Please fill in all fields."
return
}
guard isValidEmail(email) else {
errorMessage = "Please enter a valid email address."
return
}
// Start loading
isLoading = true
// Simulate a network request with a 3 second delay
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
// Stop loading
isLoading = false
// Perform your sign-in logic here
// ...
}
}
func isValidEmail(_ email: String) -> Bool {
// Basic email validation regex
let emailRegex = "^[A-Z0-9a-z._%+-]+@[A-Z0-9a-z.-]+\\.[A-Za-z]{2,64}$"
let emailPredicate = NSPredicate(format:"SELF MATCHES %@", emailRegex)
return emailPredicate.evaluate(with: email)
}
}
#Preview {
LoginView()
}
Simple Login Page
import SwiftUI
struct LoginView: View {
@State private var email: String = ""
@State private var password: String = ""
@State private var isLoading: Bool = false
@State private var errorMessage: String?
var body: some View {
VStack(spacing: 20) {
Spacer()
// Lock icon
Image(systemName: "lock.fill")
.resizable()
.scaledToFit()
.frame(width: 50, height: 50)
.foregroundColor(.blue)
.padding(.bottom, 20)
// Welcome text
Text("Welcome to ")
.font(.title)
.fontWeight(.bold) +
Text("SwiftUI.art")
.font(.title)
.fontWeight(.bold)
.foregroundColor(.blue)
// Subtitle text
Text("Log in to your account")
.font(.subheadline)
.foregroundColor(.gray)
// Email TextField
TextField("Email address", text: $email)
.padding()
.background(Color(.secondarySystemBackground))
.cornerRadius(8)
.autocapitalization(.none)
.keyboardType(.emailAddress)
.textContentType(.emailAddress)
// Password SecureField
SecureField("Password", text: $password)
.padding()
.background(Color(.secondarySystemBackground))
.cornerRadius(8)
.textContentType(.password)
// Error message
if let errorMessage = errorMessage {
Text(errorMessage)
.foregroundColor(.red)
.font(.footnote)
.padding([.top, .horizontal])
}
// Sign In button
Button(action: {
signIn()
}) {
if isLoading {
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: .white))
.frame(maxWidth: .infinity)
.padding()
} else {
Text("Sign in")
.foregroundColor(.white)
.frame(maxWidth: .infinity)
.padding()
}
}
.background(Color.black)
.cornerRadius(8)
.disabled(isLoading)
// Face ID button
Button(action: {
// Action for Face ID
}) {
HStack {
Image(systemName: "faceid")
.foregroundColor(.black)
Text("Face ID")
.foregroundColor(.black)
}
.frame(maxWidth: .infinity)
.padding()
.background(Color(.secondarySystemBackground))
.cornerRadius(8)
}
Spacer()
// Disclaimer text
Text("By clicking \"Sign in\" above, you agree to SwiftUI.art's Terms & Conditions and Privacy Policy.")
.font(.footnote)
.foregroundColor(.gray)
.multilineTextAlignment(.center)
.padding(.horizontal, 20)
Spacer()
}
.padding()
}
func signIn() {
// Reset the error message
errorMessage = nil
// Validate email and password
guard !email.isEmpty, !password.isEmpty else {
errorMessage = "Please fill in all fields."
return
}
guard isValidEmail(email) else {
errorMessage = "Please enter a valid email address."
return
}
// Start loading
isLoading = true
// Simulate a network request with a 3 second delay
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
// Stop loading
isLoading = false
// Perform your sign-in logic here
// ...
}
}
func isValidEmail(_ email: String) -> Bool {
// Basic email validation regex
let emailRegex = "^[A-Z0-9a-z._%+-]+@[A-Z0-9a-z.-]+\\.[A-Za-z]{2,64}$"
let emailPredicate = NSPredicate(format:"SELF MATCHES %@", emailRegex)
return emailPredicate.evaluate(with: email)
}
}
#Preview {
LoginView()
}